当前位置: 技术问答>java相关
就要考scjp1.4了,有几道题还不是很清楚,请大家帮忙看一看
来源: 互联网 发布时间:2017-03-18
本文导语: 88. ClassOne.java package com.ab.pkg1; public class ClassOne{ private char var='a'; char getVar(){ return var;} } ClassTest.java package com.ab.pkg2; import com.ab.pkg1.ClassOne; public class ClassTest ex...
88. ClassOne.java
package com.ab.pkg1;
public class ClassOne{
private char var='a';
char getVar(){ return var;}
}
ClassTest.java
package com.ab.pkg2;
import com.ab.pkg1.ClassOne;
public class ClassTest extends ClassOne{
public static void main(String args[]){
char a=new ClassOne().getVar();
char b=new ClassTest().getVar();
}
}
what is the result?
answer:compile error
101. which one is true?
A.An anonymous class can be declared as static.
B.A static inner class cannot be a static member of the outer class.
C.A static inner class does require an instance of the enclosing class.
D.Instance member of a static inner class can be referened using the class name of the
static inner class.
answer:c
11. Which two demonstrate an “is a” relationship? (Choose Two)
A. public interface Person { }
public class Employee extends Person { }
B. public interface Shape { }
public class Employee extends Shape { }
C. public interface Color { }
public class Employee extends Color { }
D. public class Species { }
public class Animal (private Species species;)
E. interface Component { }
Class Container implements Component (
Private Component[ ] children;
)
answer:D,E
55. Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method
B. Calling the wait method on an object
C. Calling the notify method on an object
D. Calling the NotifyAll method on an object
E. Calling the start method on another Thread object
answer:A,E
57. Given:
1. public class SyncTest (
2. private int x;
3. private int y;
4. private synchronized void setX (int i) (x=1;)
5. private synchronized void setY (int i) (y=1;)
6. public void setXY(int 1)(set X(i); setY(i);)
7. public synchronized Boolean check() (return x !=y;)
8. )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true
B. Check() can return true when setXY is called by multiple threads
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.
answer:B
74. Click the exhibit button:
1. public class Mycircle { 2. public double radius; 3. public double diameter; 4. 5. public void setRadius(double radius) 6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 9. 10. public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
answer:B
89. Given:
1. public interface Foo{
2. int k = 4;
3. }
Which three are equivalent to line 2? (Choose Three)
A.final int k = 4;
B.public int k = 4;
C.static int k = 4;
D.private int k = 4;
E.abstract int k = 4;
F.volatile int k = 4;
G.transient int k = 4;
H.protected int k = 4;
answer:A,B,C
91. Which of the following two are valid declarations of a char? (Choose Two)
A.char ch = “a”;
B.char ch = ‘’ ‘;
C.char ch = ‘cafe’;
D.char ch = “cafe”;
E.char ch = ‘ucafe’;
F.char ch = ‘u10100’;
G.char ch = (char) true;
answer:B,E
101. Which statement is true?
A. The Error class is a untimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.
answer:D
129. Which two create an instance of an array? (Choose Two)
A. int[] ia = new int [15];
B. float fa = new float [20];
C. char[] ca = “Some String”;
D. Object oa = new float[20];
E. Int ia [][] = (4, 5, 6) (1, 2, 3)
answer:A,D
130. Given:
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/ {
5. runTest ();
6. }
7. }
At point X on line 4, which code can be added to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
answer:B
142. Which two statements are true? (Choose Two)
A.An anonymous inner class can be declared inside of a method.
B.An anonymous inner class constructor can take arguments in some situation.
C.An anonymous inner class that is a direct subclass that is a direct subclass of Object can implement multiple interfaces .
D.Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface.
E.Event if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements multiple interfaces.
answer:A,B
package com.ab.pkg1;
public class ClassOne{
private char var='a';
char getVar(){ return var;}
}
ClassTest.java
package com.ab.pkg2;
import com.ab.pkg1.ClassOne;
public class ClassTest extends ClassOne{
public static void main(String args[]){
char a=new ClassOne().getVar();
char b=new ClassTest().getVar();
}
}
what is the result?
answer:compile error
101. which one is true?
A.An anonymous class can be declared as static.
B.A static inner class cannot be a static member of the outer class.
C.A static inner class does require an instance of the enclosing class.
D.Instance member of a static inner class can be referened using the class name of the
static inner class.
answer:c
11. Which two demonstrate an “is a” relationship? (Choose Two)
A. public interface Person { }
public class Employee extends Person { }
B. public interface Shape { }
public class Employee extends Shape { }
C. public interface Color { }
public class Employee extends Color { }
D. public class Species { }
public class Animal (private Species species;)
E. interface Component { }
Class Container implements Component (
Private Component[ ] children;
)
answer:D,E
55. Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method
B. Calling the wait method on an object
C. Calling the notify method on an object
D. Calling the NotifyAll method on an object
E. Calling the start method on another Thread object
answer:A,E
57. Given:
1. public class SyncTest (
2. private int x;
3. private int y;
4. private synchronized void setX (int i) (x=1;)
5. private synchronized void setY (int i) (y=1;)
6. public void setXY(int 1)(set X(i); setY(i);)
7. public synchronized Boolean check() (return x !=y;)
8. )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true
B. Check() can return true when setXY is called by multiple threads
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.
answer:B
74. Click the exhibit button:
1. public class Mycircle { 2. public double radius; 3. public double diameter; 4. 5. public void setRadius(double radius) 6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 9. 10. public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
answer:B
89. Given:
1. public interface Foo{
2. int k = 4;
3. }
Which three are equivalent to line 2? (Choose Three)
A.final int k = 4;
B.public int k = 4;
C.static int k = 4;
D.private int k = 4;
E.abstract int k = 4;
F.volatile int k = 4;
G.transient int k = 4;
H.protected int k = 4;
answer:A,B,C
91. Which of the following two are valid declarations of a char? (Choose Two)
A.char ch = “a”;
B.char ch = ‘’ ‘;
C.char ch = ‘cafe’;
D.char ch = “cafe”;
E.char ch = ‘ucafe’;
F.char ch = ‘u10100’;
G.char ch = (char) true;
answer:B,E
101. Which statement is true?
A. The Error class is a untimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.
answer:D
129. Which two create an instance of an array? (Choose Two)
A. int[] ia = new int [15];
B. float fa = new float [20];
C. char[] ca = “Some String”;
D. Object oa = new float[20];
E. Int ia [][] = (4, 5, 6) (1, 2, 3)
answer:A,D
130. Given:
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/ {
5. runTest ();
6. }
7. }
At point X on line 4, which code can be added to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
answer:B
142. Which two statements are true? (Choose Two)
A.An anonymous inner class can be declared inside of a method.
B.An anonymous inner class constructor can take arguments in some situation.
C.An anonymous inner class that is a direct subclass that is a direct subclass of Object can implement multiple interfaces .
D.Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface.
E.Event if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements multiple interfaces.
answer:A,B
|
88.ClassOne的getVar()没有modifier,默认是friendly,只有同一个package里面的class才可以调用。ClassTest处在不同的package里面。
|
130. Given:
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/ {
5. runTest ();
6. }
7. }
At point X on line 4, which code can be added to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
answer:B
答案应该是A吧....
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/ {
5. runTest ();
6. }
7. }
At point X on line 4, which code can be added to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
answer:B
答案应该是A吧....
|
这个是转义,'就是'
|
同意: chenyuan_tongji(codeguru)
11题,我问过了,就因该选E,D是has a 关系!
130题,也应该是A.142题我认为该是A,E.
11题,我问过了,就因该选E,D是has a 关系!
130题,也应该是A.142题我认为该是A,E.
|
你们准备的好充分啊
|
74题在310-035里面出现过,考完都不知道正确答案
哪位大虾出来指正一下?我选了D
哪位大虾出来指正一下?我选了D
|
74. Click the exhibit button:
1. public class Mycircle { 2. public double radius; 3. public double diameter; 4. 5. public void setRadius(double radius) 6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 9. 10. public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
answer:B
---------------------我觉得还是应该选b
d ----由于setRadius(double radius) 中得变量是radius ,但在这个方法中却同时要处理两个类变量radius ,和 diameter。由于radius是作为参数传进来的(引用)所以radius不会被这个方法修改,但是diameter确要在这个方法中修改,用this.diameter----所以,这个类变量会被这个方法修改affecting.
1. public class Mycircle { 2. public double radius; 3. public double diameter; 4. 5. public void setRadius(double radius) 6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 9. 10. public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
answer:B
---------------------我觉得还是应该选b
d ----由于setRadius(double radius) 中得变量是radius ,但在这个方法中却同时要处理两个类变量radius ,和 diameter。由于radius是作为参数传进来的(引用)所以radius不会被这个方法修改,但是diameter确要在这个方法中修改,用this.diameter----所以,这个类变量会被这个方法修改affecting.
|
101题,不太明白,我觉得该是D 呀,请大家指教!
|
我也觉得74应该选d,因为radius,diameter都是public的,修订他们就不一定要通过setRadius()方法。所以不能保证The diameter of a given MyCircle is guaranteed to be twice its radius
|
对!!楼上说得对!对于public的field是没有封装的!可以被外部修改!!
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。