|
|
/** * * @author yaoyuan */public class CertKiller{int x = 12;public void method(int x){x += x;System.out.println(x);}}Given the exhibit:21test t= new CertKiller();22t.method(5);
/**
*What is the ouput from line 5 of the CertKiller class?
*
*
*A5
*B10
*C12
*D17
*E24
*/
//Answer B
/** * * @author yaoyuan */10class CertKiller1{11public CertKiller1 Foo(){ return this;}12}13class CertKiller2 extends CertKiller1{14public CertKiller1 Foo(){return this;}15}16class CertKiller3 extends CertKiller2{17//insert code here18}/**
*Which two methods, inserted individually , correctlly complete the CertKiller3 class?(choose two)
*
*
*Apublic void foo(){}
*Bpublic int foo(){return 3;}
*Cpublic CertKiller2 foo(){return this;}
*Dpublic CertKiller1 foo(){return this;}
*/
//Answer: C D
/** * * @author yaoyuan */11public class Bootchy{12int bootch;13String snootch;1415public Bootchy(){16this("snootchy");17System.out.print("First " );18}1920public Bootchy(String snootch){21this(420, "snootchy");22System.out.print("Second ");23}2425public Bootchy(int bootch, String snoothy){26this.bootch = bootch;27this.snootch = snootch;28System.out.print("Third ");29}3031public static void main(String[] args){32Bootchy b = new Bootchy();33System.out.print(b.snootch + " " + b.bootch);34}35}
/**
*What is the result?
*
*
*Asnootchy 420 Third Second First
*Bsnootchy 420 First Second Third
*CFirst Second Third snootchy 420
*DThird Second First snootchy 420
*EThird First Second snootchy 420
*FFirst Second First Third snootchy 420
*/
//Answer D
/** * * @author yaoyuan */11public static void main(String[] args){12Object obj = new int[]{1,2,3};13int[] someArray = (int[])obj;14for(int I : someArray) System.out.print(I + " ");15}
/**
*What is the result?
*
*A1 2 3
*BCompilition fails because of an error in line 12
*CCompilition fails because of an error in line 13
*DCompilition fails because of an error in line 14
*EA ClassCaseException is thrown at runtime
*/
//Answer : A
/**
*
* @author yaoyuan
*/
/**
*A Java Bean component has the following field:
*11.PRIVATE BOOLEAN ENABLED;
*Which two pairs of method declarations follow the javabean standard for accessing this field?(choose two)
*
*
*Apublic void setEnabled(Boolean enabled)
*public Boolean getEnabled()
*Bpublic void setEnabled(Boolean enabled)
*public void isEnabled()
*Cpublic void setEnabled(Boolean enabled)
*public Boolean isEnable()
*Dpublic void setEnabled(Boolean enabled)
*public Boolean getEnabled()
*/
//Answer: A C
/**
*
* @author yaoyuan
*/
10class CertKiller{11static void alpha(){/*more code here*/}12void beta(){/*more code here*/}13}
/**
*Which two statements are true?
*
*
*ACertKiller.beta() is valid invocation of beta()
*BCertKiller.alpha() is valid invocation of alpha()
*CMethod beta() can directly call method alpha()
*DMethod alpha() can directly call method beta()
*/
//Anwser : B C
/** * * @author yaoyuan */public abstract class Shape{private int x;private int y;public abstract void draw();public void setAnchor(int x, int y){this.x = x;this.y = y;}}
/**
*Which two classes use the Shape class correctly?(choose two)
*
*Apublic class Circle implements Shape{
*private int radius;
*}
*Bpublic abstract class Circle extends Shape{
*private int radius;
*}
*Cpublic class Circle extends Shape{
*private int radius;
*public void draw();
*}
*Dpublic abstract class Circle implements Shape{
*private int radius;
*public void draw();
*}
*Epublic class Circle extends Shape{
*private int radius;
*public void draw(){/*code here*/}
*}
*Fpublic abstract class Circle implements Shape{
*private int radius;
*public void draw(){/*code here*/}
*}
*/
//Answer: B E
/** * * @author yaoyuan */11static class A {12void process() throws Exception{throw new Exception();}13}14static class B extends A{15void process(){System.out.println("B");}16}17public static void main(String[] args){18A a = new A();19A.process();20}
/**
*What is result
*
*
*
*AB
*BThe code exception is thrown at runtime
*CThe code run with no output
*DCompilition fails because of an error in line 15
*ECompilition fails because of an error in line 18
*FCompilition fails because of an error in line 19
*
*/
//Answer : F
/** * * @author yaoyuan */33try{34//some code here35}catch(NullPointerException e1){36System.out.print("a");37}catch(RuntimeException e2){38System.out.print("b");39}finally{40System.out.print("c");41}
/**
*What is the result if NullPointerException occurs on line 34?
*
*Ac
*Ba
*Cab
*Dac
*Ebc
*Fabc
*/
//Answer : D
/** * * @author yaoyuan */10public class CertKiller{11static int[] a;12static {a[0] = 2;}13public static void main(String[] args){}14}
/**
*Which exception or error will be thrown when a programmer attempts to run this code?
*
*Ajava.lang.StackOverflowError
*Bjava.lang.IllegalStateException
*Cjava.lang.Exceptio0nInInitoatializerError
*Djava.lang.ArrayIndexOutOfBoundsException
*
*/
//Answer : C |
|