浏览 2982 次
锁定老帖子 主题:SCJP认证试题(三)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (2)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-14
* * @author yaoyuan */ /** *Which three statements are true?(choose three) * *A A final method in class x can be abstract if and only if x is abstract *B A protected method in class x can be overridden by any subclass of x *C A private static method can be called only with in other static method in class x *D A non-static public final method in class x can be overridden in any subclass x *E A public static method in class x can be called by a subclass of x without explicitly referencing * the class x *F A method with the same signature as a private final method in class x can be implement entered in * a subclass of x */ // Answer : B E F /** * * @author yaoyuan */ /** *Replace two of the Modifiers that appear in the Single class to make the code compile * *Note:Three Modifiers will not be used and four midifiers in the code will remain unchanged * */ /** Code */ public class Single{ /*private*/ /*static*/ Single instance; /*public*/ /*static*/ Single getInstance(){ if(instance == null) instance = create(); return instance; } /*private*/ Single(){ } /*protected*/ Single create(){ return new Single(); } } class SingleSub extends Single{ } /** * Modifiers * * final protected private abstract static */ // Answer : // // public class Single{ // private static Single instance; // // public static Single getInstance(){ // if(instance == null) // instance = create(); // return instance; // } // protected Single(){ // // } // // static Single create(){ // return new Single(); // } // } // // class SingleSub extends Single{ // // } // // /** * * @author yaoyuan */ public class SimpleCalc{ public int value; public void calculate(){ value += 7; } } public class Multicalc extends SimpleCalc{ public void calculate(){ value -= 3; } public void calculate(int multiplier){ calculate(); super.calculate(); value *= multiplier; } public static void main(String[] args){ Multicalc calculator = new Multicalc(); calculator.calculate(2); System.out.println("Value is :" + calculator.value); } } /** *What is the result? * *A Value is :8 *B Compilation fails *C Value is :12 *D Value is :-12 *E The Code is runs with no output *F An Exception is thrown at runtime */ // Answer : A /** * * @author yaoyuan */ public class CertkillerCard{ private String cardID; private Integer limit; public String ownerName; public void setCardInformation(String cardID, String ownerName, Integer limit){ this.cardID = cardID; this.limit = limit; this.ownerName = ownerName; } } /** *Which statement is true? * * *A The class is fully encapsulated *B The code demonstrates polymorphism *C The ownerName variable breaks encapsulation *D The cardID and limit variables break polymorphism *E The setCardInformation method breaks encapsulation */ // Answer : C /** * encapsulated 封装 * polymorphism 多态 * demonstrates 展示 */ /** * * @author yaoyuan */ class Animal{ public String noise(){ return "peep"; } } class Dog extends Animal{ public String noise(){ return "back"; } } class Cat extends Animal{ public String noise(){ return "move"; } } ................... ................... ................... Animal animal = new Dog(); Cat cat = (Cat)animal; System.out.println(Cat.noise()); /** *What is the result ? * * *A peep *B bark *C move *D Compilation fails *E An exception is thrown at runtime */ // Answer : E /** * *Cat cat = (Cat)animal; 这行出错了,Dog不能强制转换成Cat对象 * */ /** * * @author yaoyuan */ public class Car{ private int wheelCount; private String vin; public Car(String vin){ this.vin = vin; this.wheelCount = 4; } public String extend(){ return "zoom zoom"; } public String getInfo(){ return "VIN:" + vin + "wheels:" + wheelCount; } } public class MeGo extends Car{ public MeGo(String vin){ this.wheelCount = 3; } } /** * What two must the programmer do to oerrect the compilation errors? * * *A insert a call to this() in the Car Constructor *B insert a call to this() in the MeGo Constructor *C insert a call to super() in the MeGo Constructor *D insert a call to super(vin) in the MeGo Constructor *E change the wheelCount variable in Car protected *F change line 3 in the MeGo class to super wheelCount =3; */ // Answer E /** * * @author yaoyuan */ 10 interface A { public int getValue();} 11 class B implements A{ 12 public int getValue(){return 1;} 13 } 14 class C extends B{ 15 [insert code here] 16 } /** *What three code fragments inserted individually at line 15, make use of polymorphism? * * *A public void add(C c){c.getValue();} *B public void add(B b){b.getValue();} *C public void add(A a){a.getValue();} *D public void add(A a, B b){a.getValue();} *E public void add(C c1, C c2){c1.getValue();} */ // Answer : B C D /** * * @author yaoyuan */ 11 certkiller = new ReallyBigObject(); 12 //more code here 13 certkiller = null; 14 /*insert code here*/ /** *Which statement should be placed at line 14 to suggest that the virtual machine expend effort tow and recycling the memory used by the Object certkiller? * * *A System.gc(); *B Runtime.gc(); *C System.freeMemory(); *D Runtime.getRuntime() growHeap() *E Runtime.getRuntime() freeMemory() */ // Answer : A /** * * @author yaoyuan */ /** *A developer is creating a class Book, that needs to access class Paper,The Paper class is deployed in a JAR named myLib.jar. *Which three, taken independently, will allow the developer to use the Paper class while compiling the Book class? (choose three) * * *A The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar *B The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar *C The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes * /foo/myLib.jar/Paper.class *D The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes * /foo/myLib.jar *E The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -cp * /foo/myLib.jar Book.java * *F The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d * * /foo/myLib.jar Book.java * *G The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath * /foo/myLib.jar Book.java */ // Answer : B D G /** * * @author yaoyuan */ 11 class Certkiller{ 12 Boochy booch; 13 public Certkiller(){booch = new Boochy(this);} 14 } 15 16 class Boochy{ 17 Certkiller smooch; 18 public Boochy(Certkiller s){smoothy = s;} 19 } and the statements: 21 public static void main(String[] args){ 22 Certkiller snoog = new Certkiller(); 23 snoog = null; 24 //more code here 25 } /** *Which statement is true about the object referenced by snoog,smooch and booch immediately after line 23 *executes? * * *A None of these objects are eligible for garbage collection *B only the object referenced by booch is eligible for garbage collection *C only the object referenced by snoog is eligible for garbage collection *D only the object referenced by smooch is eligible for garbage collection *E The Objects referenced by smooch and booch are eligible for garbage collection */ // Answer : E 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |