yuanyao 发表于 2013-2-4 22:53:41

SCJP认证试题(十一)

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

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


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

Bimport static com.sun.scjp.Geodetics;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}
Cimport static com.sun.scjp.Geodetics.*;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}
Dimport com.sun.scjp;
public class TerraCarta{
public double halfway(){
return DIAMETER/2.0;
}
}


Answer: A C
/**
*参考静态导入
*/


/** * * @author yaoyuan */10class Line{11public static class Point{}12}1314class Triangle{15//insert code here16}


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


APoint p = new Point();
BLine.Point p = new Line.Point();
CThe Point class cannot be in statiated at line 15
DLine l = new Line();l.Point p = new l.Point();


Answer : B




/** * * @author yaoyuan */1public class Plant{2private String name;3public Plant(String name){this.name = name;}4public String getName(){return name;}51public class Tree extends Plant{2public void growFruit(){}3public void dropLeaves(){}4}

Which statement is true?

AThe code will compile without changes.
BThe code will compile if public Tree(){Plant();} is added to the Tree class
CThe code will compile if public Plant(){Tree();} is added to the Plant class
DThe code will compile if public Plant(){this("fern");} is added to the Plant class
EThe code will compile if public Plant(){Plant("fern");} is added to the Plant class

Answer : D



/** * * @author yaoyuan */10public class Bar{11static void foo(int x){12//insert code here13}14}
Which two code fragments inserted indepently at line 12, will allow the class to compile?(Choose two)


Aforeach(x) System.out.println(z);
Bfor(int z : x) System.out.println(z);
Cwhile(x.hashNext()) System.out.println(x.next());
Dfor(int i=0;i<x.length;i++) System.out.println(x);


Answer : B D

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

Which statement is true?


A420 is the output
BAn exception is thrown at runtime
CAll constructors must be declared public
DConstructors cannot use the private modifier
EConstructors cannot use the protected modifier



Answer:A


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


What is the result?


Afoofoofoofoofoo
Bfoobarfoobarbar
Cfoobarfoofoofoo
Dfoobarfoobarfoo
Ebarbarbarbarbar
Ffoofoofoobarbar


Answer:D



/**
*
* @author yaoyuan
*/


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


AInheritance represents an is-a relationship
BInheritance repersents an has-a relationship
CInterfaces must be use when creating a has-a relationship
DInstance variables can be used when creating a has-a relationship


Answer:A D


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

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


AIt can be any class
BNo class has access to base
CThe class must be long to the geometry package
DThe class must be a subclass of the class Hypotenuse



Answer: C


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

What is the result?


ACompilation fails because of an error in line 3
BCompilation fails because of an error in line 7
CCompilation fails because of an error in line 9
Dif you define D e = new E(),then e.bMethod() invokes the version of bMethod() defined in line 5
Eif you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 5
Fif you define D e = (D)(new E()),then bMethod() invokes the version of bMethod() defined in line 9


Answer: F


/**
*
* @author yaoyuan
*/

Which two statements are true?(Choose two)


AAn encapsulation,public class promotes re-use
BClasses that share the same interface are always tightly encapsulated
CAn encapsulation class allow subclasses to overload methods, but does not allow overriding methods
DAn encapsulation class allow programmer to change an implementation without affecting outside code.


Answer:A D
页: [1]
查看完整版本: SCJP认证试题(十一)