当前位置: 技术问答>java相关
SCJP模拟题,请教
来源: 互联网 发布时间:2015-10-19
本文导语: 2. Given: Integer i = new Integer (42); Long 1 = new Long (42); Double d = new Double (42.0); Which two expressions evaluate to True? (Choose Two) A. (i ==1) B. (i == d) C. (d == 1) D. (i.equals (d)) E. (d.equals (i)) F. (i.equals (42)) 我试...
2. Given:
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
我试了一下好象没有对的呀
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))
我试了一下好象没有对的呀
|
a b c 都不符合语法规范,因为i d l 都是对象,不能用 == 来判断
f 也不符合语法规范,因为equals方法比较的是两个对象的值 int 数42 显然不是对象。
就盛d 和 e 了,可是浮点数42,与整形数42.0值是不同的呀。那就没有答案吧,scjp考试题里规定可以有没有答案的题。
f 也不符合语法规范,因为equals方法比较的是两个对象的值 int 数42 显然不是对象。
就盛d 和 e 了,可是浮点数42,与整形数42.0值是不同的呀。那就没有答案吧,scjp考试题里规定可以有没有答案的题。
|
answer is wrong
|
de,不对,那就没有答案了
12 D
12 D
|
a b c 都不符合语法规范,因为i d l 都是对象,不能用 == 来判断
f 也不符合语法规范,因为equals方法比较的是两个对象的值 int 数42 显然不是对象。
就盛d 和 e 了,可是浮点数42,与整形数42.0值是不同的呀。那就没有答案吧,scjp考试题里规定可以有没有答案的题。
我同意这位大虾的看法,equal()的用法要求对比的两个Object必须类型一致,值相同,才会返回true。
注:Compares this object against the specified object. The result is true if and only if the argument is not null and is a Double object that represents a double that has the same value as the double represented by this object.
f 也不符合语法规范,因为equals方法比较的是两个对象的值 int 数42 显然不是对象。
就盛d 和 e 了,可是浮点数42,与整形数42.0值是不同的呀。那就没有答案吧,scjp考试题里规定可以有没有答案的题。
我同意这位大虾的看法,equal()的用法要求对比的两个Object必须类型一致,值相同,才会返回true。
注:Compares this object against the specified object. The result is true if and only if the argument is not null and is a Double object that represents a double that has the same value as the double represented by this object.
|
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package foo;
public class Outer
{
public static class Inner
{
public void writeSt()
{
System.out.println("Hello");
}
}
}
class TryInner
{
public TryInner()
{
new Outer.Inner(); //-------------A is OK!!!! and C is wrong.
}
}
***************
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package bar;
class TryPack
{
public static void main(String[] args)
{
System.out.println("Hello World!");
//new Inner(); -----------This line is wrong so D is wrong;
new foo.Outer.Inner(); // You should write like this. and B is wrong
}
}
************************The Answer is A
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package foo;
public class Outer
{
public static class Inner
{
public void writeSt()
{
System.out.println("Hello");
}
}
}
class TryInner
{
public TryInner()
{
new Outer.Inner(); //-------------A is OK!!!! and C is wrong.
}
}
***************
/**
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
*/
package bar;
class TryPack
{
public static void main(String[] args)
{
System.out.println("Hello World!");
//new Inner(); -----------This line is wrong so D is wrong;
new foo.Outer.Inner(); // You should write like this. and B is wrong
}
}
************************The Answer is A
|
没有正确答案
equals在比较示范时类型不一致的一律返回false
equals在比较示范时类型不一致的一律返回false
|
这是一个static inner class.所以A是正确的。