SCJP认证试题(十一)

 /**
*
* @author yaoyuan
*/
10 package com.sun.scjp;
11 public class Geodetics{
12 public static final double DIAMETER = 12756.32; //kilometers
13 }


Which two correctly access the DIAMETER member of the Geodetics class?(choose two)


A import com.sun.scjp.Geodetics;
public class TerraCarta{
public double halfway(){
return Geodetics.DIAMETER/2.0;
}
}

B import static com.sun.scjp.Geodetics;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}
C import static com.sun.scjp.Geodetics.*;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}
D import com.sun.scjp;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}


[color=red]Answer: A C[/color]
/**
*参考静态导入
*/



/**
*
* @author yaoyuan
*/
10 class Line{
11 public static class Point{}
12 }
13
14 class Triangle{
15 //insert code here
16 }



Which code inserted line 15, creates an instance of the Point class defined in Line?


A Point p = new Point();
B Line.Point p = new Line.Point();
C The Point class cannot be in statiated at line 15
D Line l = new Line(); l.Point p = new l.Point();

[color=red]
Answer : B
[/color]


 /**
*
* @author yaoyuan
*/
1 public class Plant{
2 private String name;
3 public Plant(String name){this.name = name;}
4 public String getName(){return name;}
5

1 public class Tree extends Plant{
2 public void growFruit(){}
3 public void dropLeaves(){}
4 }


Which statement is true?

A The code will compile without changes.
B The code will compile if public Tree(){Plant();} is added to the Tree class
C The code will compile if public Plant(){Tree();} is added to the Plant class
D The code will compile if public Plant(){this("fern");} is added to the Plant class
E The code will compile if public Plant(){Plant("fern");} is added to the Plant class

[color=red]Answer : D[/color]


 /**
*
* @author yaoyuan
*/

10 public class Bar{
11 static void foo(int x){
12 //insert code here
13 }
14 }


Which two code fragments inserted indepently at line 12, will allow the class to compile?(Choose two)


A foreach(x) System.out.println(z);
B for(int z : x) System.out.println(z);
C while(x.hashNext()) System.out.println(x.next());
D for(int i=0;i<x.length;i++) System.out.println(x[i]);

[color=red]
Answer : B D[/color]


/**
*
* @author yaoyuan
*/

1 class ClassA{
2 public int numberOfInstances;
3 protected ClassA(int numberOfInstances){
4 this.numberOfInstances = numberOfInstances;
5 }
6 }
7 public class ExtendedA extends ClassA{
8 private ExtendedA(int numberOfInstances){
9 super(numberOfInstances);
10 }
11 public static void main(String[] args){
12 ExtendedA ext = new ExtendedA(420);
13 System.out.print(ext.numberOfInstances);
14 }
15 }


Which statement is true?


A 420 is the output
B An exception is thrown at runtime
C All constructors must be declared public
D Constructors cannot use the private modifier
E Constructors cannot use the protected modifier


[color=red]Answer: A[/color]


 /**
*
* @author yaoyuan
*/

1 public class Base{
2 public static final String FOO = "foo";
3 public static void main(String[] args){
4 Base b = new Base();
5 Sub s = new Sub();
6 System.out.print(Base.FOO);
7 System.out.print(Sub.FOO);
8 System.out.print(b.FOO);
9 System.out.print(s.FOO);
10 System.out.print(((Base)s).FOO);
11 }}
12 class Sub extends Base{public static final String FOO = "bar";}



What is the result?


A foofoofoofoofoo
B foobarfoobarbar
C foobarfoofoofoo
D foobarfoobarfoo
E barbarbarbarbar
F foofoofoobarbar


[color=red]Answer: D
[/color]


/**
*
* @author yaoyuan
*/


Which two statements are true about has-a and is-a relationships?(Choose two)


A Inheritance represents an is-a relationship
B Inheritance repersents an has-a relationship
C Interfaces must be use when creating a has-a relationship
D Instance variables can be used when creating a has-a relationship


[color=red]Answer:A D[/color]


 /**
*
* @author yaoyuan
*/

1 package geometry;
2 public class Hypotenuse{
3 public InnerTriangle it = new InnerTriangle();
4 class InnerTriangle{
5 public int base;
6 public int height;
7 }
8 }


Which statement is true about the class of an object that can reference the variable base?


A It can be any class
B No class has access to base
C The class must be long to the geometry package
D The class must be a subclass of the class Hypotenuse


[color=red]Answer: C[/color]


 /**
*
* @author yaoyuan
*/

1 interface A{public void aMethod();}
2 interface B{public void bMethod();}
3 interface C extends A,B{public void cMethod();}
4 class D implements B{
5 public void bMethod(){}
6 }
7 class E extends D implements C{
8 public void aMethod(){}
9 public void bMethod(){}
10 public void cMethod(){}
11 }



What is the result?


A Compilation fails because of an error in line 3
B Compilation fails because of an error in line 7
C Compilation fails because of an error in line 9
D if you define D e = new E(),then e.bMethod() invokes the version of bMethod() defined in line 5
E if you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 5
F if you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 9


[color=red]Answer: F[/color]


/**
*
* @author yaoyuan
*/

Which two statements are true?(Choose two)


A An encapsulation,public class promotes re-use
B Classes that share the same interface are always tightly encapsulated
C An encapsulation class allow subclasses to overload methods, but does not allow overriding methods
D An encapsulation class allow programmer to change an implementation without affecting outside code.


[color=red]Answer:A D[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值