read.pudn.comread.pudn.com/downloads92/doc/359648/sun java2 final.doc  · web view1. which...

102
COOLCRAM Lab 1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift B. >> performs a rotate C. >> performs a signed and >>> performs an unsigned shift D. >> performs an unsigned and >>> performs a signed shift E. >> should be used on integrals and >>> should be used on floating point types C. 2. Given the following declaration String s = "Example"; Which are legal code? A. s >>> = 3; B. s[3] = "x"; C. int i = s.length(); D. String t = "For " + s; E. s = s + 10; CDE. 3. Given the following declaration String s = "hello"; Which are legal code? A. s >> = 2; B. char c = s[3]; C. s += "there"; D. int i = s.length(); E. s = s + 3; CDE. 4. Which statements are true about listeners? A. The return value from a listener is of boolean type. B. Most components allow multiple listeners to be added. C. A copy of the original event is passed into a listener method. D. If multiple listeners are added to a single component, they all must all be friends to each other. E. If the multiple listeners are added to a single component, the order [in which listeners are called is guaranteed]. BC. 5. What might cause the current thread to stop executing. A. An InterruptedException is thrown. B. The thread executes a wait() call. C. The thread constructs a new Thread. D. A thread of higher priority becomes ready. E. The thread executes a waitforID() call on a MediaTracker. ABDE. 6. Given the following incomplete method. 1. public void method(){ 2. 3. if (someTestFails()){ 4. 5. } 6. 7.} You want to make this method throw an IOException if, and only if, the method someTestFails() returns a value of true. Which changes achieve this? A. Add at line 2: IOException e; B. Add at line 4: throw e; C. Add at line 4: throw new IOException(); D. Add at line 6: throw new IOException(); E. Modify the method declaration to indicate that an object of [type] Exception might be thrown. CE. 7. Which modifier should be applied to a method for the lock of the

Upload: others

Post on 15-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

COOLCRAM Lab1. Which statement are characteristics of the >> and >>> operators.A. >> performs a shiftB. >> performs a rotateC. >> performs a signed and >>> performs an unsigned shiftD. >> performs an unsigned and >>> performs a signed shiftE. >> should be used on integrals and >>> should be used on floatingpoint typesC.2. Given the following declarationString s = "Example";Which are legal code?A. s >>> = 3;B. s[3] = "x";C. int i = s.length();D. String t = "For " + s;E. s = s + 10;CDE.3. Given the following declarationString s = "hello";Which are legal code?A. s >> = 2;B. char c = s[3];C. s += "there";D. int i = s.length();E. s = s + 3;CDE.4. Which statements are true about listeners?A. The return value from a listener is of boolean type.B. Most components allow multiple listeners to be added.C. A copy of the original event is passed into a listener method.D. If multiple listeners are added to a single component, they all mustall be friends to each other.E. If the multiple listeners are added to a single component, the order[in which listeners are called is guaranteed].BC.5. What might cause the current thread to stop executing.A. An InterruptedException is thrown.B. The thread executes a wait() call.C. The thread constructs a new Thread.D. A thread of higher priority becomes ready.

E. The thread executes a waitforID() call on a MediaTracker.ABDE.6. Given the following incomplete method.1. public void method(){2.3. if (someTestFails()){4.5. }6.7.}You want to make this method throw an IOException if, and only if, themethod someTestFails() returns a value of true.Which changes achieve this?A. Add at line 2: IOException e;B. Add at line 4: throw e;C. Add at line 4: throw new IOException();D. Add at line 6: throw new IOException();E. Modify the method declaration to indicate that an object of [type]Exception might be thrown.CE.7. Which modifier should be applied to a method for the lock of theobject this to be obtained prior to executing any of the method body?A. finalB. staticC. abstractD. protectedE. synchronizedE.8. Which are keywords in Java?A. NULLB. trueC. sizeofD. implementsE. instanceofDE.9. Consider the following code:Integer s = new Integer(9);Integer t = new Integer(9);Long u = new Long(9);Which test would return true?A. (s==u)B. (s==t)C. (s.equals(t))D. (s.equals(9))E. (s.equals(new Integer(9))CE.

Page 2: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

10. Why would a responsible Java programmer want to use a nested class?A. To keep the code for a very specialized class in close associationwith the class it works with.B. To support a new user interface that generates custom events.C. To impress the boss with his/her knowledge of Java by using nestedclasses all over the place.AB.11. You have the following code. Which numbers will cause "Test2" to beprinted?switch(x){case 1:System.out.println("Test1");case 2:case 3:System.out.println("Test2");break;}System.out.println("Test3");}A. 0B. 1C. 2D. 3E. 4BCD.12. Which statement declares a variable a which is suitable forreferring to an array of 50 string objects?A. char a[][];B. String a[];C. String []a;D. Object a[50];E. String a[50];F. Object a[];BCF.13. What should you use to position a Button within an applicationframe so that the width of the Button is affected by the Frame size butthe height is not affected.A. FlowLayoutB. GridLayoutC. Center area of a BorderLayoutD. East or West of a BorderLayoutE. North or South of a BorderLayoutE.14. What might cause the current thread to stop executing?A. An InterruptedException is thrown

B. The thread executes a sleep() callC. The thread constructs a new ThreadD. A thread of higher priority becomes ready (runnable)E. The thread executes a read() call on an InputStreamABDE.Non-runnable states:* Suspended: caused by suspend(), waits for resume()* Sleeping: caused by sleep(), waits for timeout* Blocked: caused by various I/O calls or by failing to get a monitor'slock, waits for I/O or for the monitor's lock* Waiting: caused by wait(), waits for notify() or notifyAll()* Dead: Caused by stop() or returning from run(), no way out15. Consider the following code:String s = null;Which code fragments cause an object of type NullPointerException to bethrown?A. if((s!=null) & (s.length()>0))B. if((s!=null) &&(s.length()>0))C. if((s==null) | (s.length()==0))D. if((s==null) || (s.length()==0))AC.16. Given the following method body:{if (sometest()) {unsafe();}else {safe();}}The method "unsafe" might throw an IOException (which is not a subclassof RunTimeException). Which correctly completes the method ofdeclaration when added at line one?A. public void methodName() throws ExceptionB. public void methodname()C. public void methodName() throw IOExceptionD. public void methodName() throws IOExceptionE. public IOException methodName()AD.17. What would be the result of attempting to compile and run the

Page 3: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

following piece of code?public class Test {static int x;public static void main(String args[]){System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. An object of type NullPointerException is thrown.C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type ArrayIndexOutOfBoundsException is thrown.A.18. What would be the result of attempting to compile and run thefollowing piece of code?public class Test {public int x;public static void main(String args[]){System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. Non-static variable x cannot be referenced from a static context..C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type ArrayIndexOutOfBoundsException is thrown.B.19. What would be the result of attempting to compile and run thefollowing piece of code?public class Test {public static void main(String args[]){int x;System.out.println("Value is " + x);}}A. The output "Value is 0" is printed.B. An object of type NullPointerException is thrown.C. An "illegal array declaration syntax" compiler error occurs.D. A "possible reference before assignment" compiler error occurs.E. An object of type

ArrayIndexOutOfBoundsException is thrown.D.310-025TOPBIBLETOPbible lab. 2001.91.public static void main(String args[]) {Boolean a[]=new Boolean[4];int I= 1;System.out.println(a[I]); }What will be printed?Compilation Error in Line 2Compilation Error in line 4Exception in Line 4Will print trueWill print falseWill print nullAns:F2.public static void main(String args[]) {Integer b= new Integer(10);Add(b);System.out.println(b.intvalue());}void Add(Integer b){int I= b.intvalue();I+=3;b= new Integer(I)}What will be printed out?Will print 13Will print 10Compilation Error in Line 4 ?. implicit conversion to Integer toString is not possibleCompilation Error in line 10 you can't re initialize a WrapperclassException in Line 10Ans:bclass text{public static void main(String args[]){String a =args[1];String b =args[2];String c =args[3];

Page 4: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

}}if you will execute java text cat dog sheep what will be the value ofthe 'c' ?catdogsheepCompilation ErrorException will occurAns:E4. public static void main(String args[]){Float f=new Float(4.2f);Float c;Double d=new Double(4.2);float fl=4.2f;c=f;}which will return true?. Select allf.equls(d)c==fc==dc.equls(f)Ans:B,D5. public static void main(String args[]){String s;System.out.println("s = "+s);}what will be printed out?Compilation ErrorAn Exception will occurWill print s= nullWill print s=Ans:A6. class s extends Thread{int j=0;public void run() {try{Thread.sleep(5000);}catch(Exception e){}j=100;}public static void main(String args[]){s t1=new s();t1.start();System.out.println(t1.j);}

}what you have to do to ensure that 'j' will print 100you have make t1 as Daemon ThreadYou have join the t1 to mainYou have to suspend the main when the thread starts and resume it afterthe value of 'j' is set to 100You have to interrupt the main threadAns:B7. What will happen if you compile/run this code?1: public class Q1 implements Runnable2: {3: public void run(String s)4: {5: System.out.println("Before start Thread :"+s);6:7: System.out.println("After stop of Thread :"+s);8: }9:10: public static void main(String[] args)11: {12: Q1 a = new Q1();13: Thread t=new Thread(a);14: t.start();}15: }A) Compilation error at line 1B) Runtime exception at line 13.C) Compilation error at line 14D) Prints "Before start of Thread "After Start of ThreadAns:A8. class s implements Runnable{int x=0,y=0;int addX(){x++; return x;}int addY(){y++; return y;}public void run(){for(int i=0;i<10;i++)System.out.println(addX()+""+addY());}public static void main(String args[])

Page 5: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

{s run=new s();Thread t1=new Thread(run);Thread t2=new Thread(run);t1.start();t2.start();}}Compile time Error There is no start methodWill print in this order 11 22 33……Will print but not exactly in an order (eg: 123124 3……)Will print in this order 12 3……123……Will print in this order 123……?.Ans:C9.class s implements Runnable{int x=0,y=0;synchronized void addX(){x++; }synchronized void addY(){y++; }void addXY(){x++;y++;}boolean check() { return (x>y)? true:false;)public void run(){////System.out.println(check()); }public static void main(String args[]){ s run=new s();Thread t1=new Thread(run);Thread t2=new Thread(run);t1.start();t2.start();}}If this methods are called in which order the check will return true?Select all that applycall addX() and addY() simultaneously for number of times in run()call addY() and addX() simultaneously for number of times in run()all addXY() for number of times in run()Ans:B,C10. What is the name of the method

used to start a thread execution?A. init();B. start();C. run();D. resume();Ans:B11. Which two methods may not directly cause a thread to stopexecuting?A. sleep();B. stop();C. yield();D. wait();E. notify();F. notifyAll()G. synchronized()Ans:EF12. class Outer{class Inner{}}How will you create an instance of Inner Class out side? Select 2Inner a= new Inner();Outer o= new Outer();Inner a= new o.Inner();Outer o= new Outer();Outer.Inner a= new o.Inner();Outer.Inner a= new Outer().new Inner();Ans:CD13. What a static inner class can access select oneA. Any variables in the enclosing scopeB. Final variables in the enclosing scopeC. Static variables declared in side the methodD. Static variables declared in side the outer classAns:D14. What is true about inner class? Select onean Inner class can access all variables in the any enclosing scopean Inner class can access all variables in the enclosing scopean inner class can be declared as privatean Anonymous inner class can be

Page 6: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

extended from class and can implementan interfaceAns:C15. A ----- is a class that is a collection which cannot contain anyduplicate elements which maintains its elements in ascending order.SortedSetSetSorted MapCollectionTreeSetAns: A16. What is true about Map select oneA map will order the elements in an order according the keyA map will use unique key to store valueA map will use unique key to identify value inside the mapAns:C17. Which Method Returns the parent part of the pathname of this Fileobject, or null if the name has no parent part?getParent()getParentDir()getParentDirectory()parentDirectory()Ans:a18. Which class should be used in situations that require writingcharacters rather than bytes.LineNumberWriterPrintWriterPrintStreamPrintOutputReaderAns:B19. To Write End of a File f=new File(C:\\hello.txt");new RandomAccessFile(f,"rw").writeByte(?;FileInputStream fis=new FileInputStream(f,true);DataInputStream d=new DatainputStream(fis);

d.writeBytes(?FilterInputStream fis=new FilterInputStream(f,true);DataInputStream d=new DatainputStream(fis);d.writeBytes(?D. FileOutputStream fis=new FileOutputStream(f);DataOutputStream d=new DataOutputStream(fis);d.writeBytes(?E. FilterOutputStream fis=new FilterOutputStream(f);DataOutputStream d=new DataOutputStream(fis);d.writeBytes(?Ans:C//Random access file needs to use seek() in order to write last20. Which of the following is the correct form of constructor forPrintWriter?new PrintWriter(new OutputStreamReader(new File(".\hai.txt");new PrintWriter(new File(".\hai.txt");new PrintWriter(new OutputStream());21. What is the return-type of the getSource of ActionEvent?A. booleanB. BooleanC. voidD. ID of the eventE. ObjectAns:E22. To Retrieve the cosine which method you will use?coscosinegetCosgetCosineAns:A23. Which class is handling Events for MouseMotionListener?MouseMotionEventMouseEventMotionEventActionEventAns:B

Page 7: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

24. Which of the following will create an empty file. select 2FileInputStreamRandomAccessFile is constructed as "rw".FileOutputStream.Ans:A,B25. import java.util.Stack;public class aClass{public static void main(String []agrs){Stack st1 = new Stack();Stack st2 = new Stack();new aClass().Method(st1, st2);System.out.println("st1 has: " + st1);System.out.println("st2 has: " + st2);}private void Method(Stack st1,Stack st2){st2.push(new Integer(100));st1 = st2;}}A. printst1 has: []st2 has: [100]B. error in st1 = st2C. error in ("st1 has: " + st1)D. printst1 has: [100]st2 has: [100]Ans:A26. class Super{int i=0;Super(String s){i=10;}}class Sub extends Super{Sub(String s){ i=20; }public static void main(String args[]){Sub b=new Sub("hello");System.out.println(i);

}What will be the value of i.?A. Compilation ErrorB. Runtime ErrorC. 0D. 10E. 20Ans:E27. String s= "ABCD";s.concat("E");s.replace('C','F');System.out.println(s);What will be printed out?A. Compilation Error says that String is immutableB. ABFDEC. ABCDED. ABCDAns:D28. class sree{fun(){static int I =0;I++;}public static void main(String args[]){sree obj=new sree();obj.fun();obj.fun();}what will be the value of I ?A. Compilation errorB. Run time ErrorC. 1D. 2Ans:A//you cannot declare a static variable inside the mehtod29. which are the correct forms of Overloading Constructors for theclass hai?public void hai(int a)hai(int a,int b)public hai(int a)int hai(int c, int d)int hai()int hai(String s)Ans:BC//contstructors will not return any

Page 8: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

valueWhich are the correct forms of overriding for the method void hai(inta,int b)public void hai(int a,int b)protected void hai(int a,int b)public hai(int a)int hai(int c, int d)int Hai()int hai(String s)Ans:A,B31. public static void main(String args[]){ try{System.out.println("1");/////AA}catch (RuntimeException x){System.out.println("2");return;}catch(Exception x){System.out.println("3");return;}finally{System.out.println("4");}System.out.println("5");}if there is no Exception in the try block what will be the output?Select all that apply?A. 1B. 2C. 3D. 4E. 5Ans:ade32. class Sree{public static void main(String args[]){ try{return ;}catch(Exception e){System.out.println("Exception");}finally{System.out.println("Finally");}

}}What will be the out put?A. Compilation Error void main Can't return any value.B. Prints ExceptionC. Prints Exception FinallyD. Prints FinallyAns:D//If there is any value with return then result will be compilationerrorclass Sree{public static void main(String args[]){System.out.println(hai());}static int hai(){try{return 1;}catch(Exception e){System.out.println("Exception");}finally{System.out.println("Finally");return 2;}}}What will be the out put?A. Compilation Error void main Can't return any value.B. Prints ExceptionC. Prints Exception FinallyD. Prints Finally and 1E.Prints Finally and 2Ans:E33. class Jith{public static void main(String args[]){try{mymethod();}catch(Exception e){System.out.println("Exception");}}}How will you declare mymethod so that it will throw a Exception? Select

Page 9: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

one?A. In method declaration give throw Exception and inside the methodgive throws ExceptionB. In method declaration give throws Exception and inside the methodgive throw ExceptionC. In method declaration give throw Exception and inside the methodgive throw ExceptionD. In method declaration give throws Exception and inside the methodgive throws ExceptionAns:A34. class Sreejith{public static void main(String args[]){try{///ProtocolException}catch(IOException e){System.out.println("I");}catch(Exception e){System.out.println("E");}finally{System.out.println("F");}}}//Exception is the super class of IOException and IOException is thesuper class of ProtocolExceptionif a ProtocolException occurs in try block what will be the out put?Select allA. IB. EC. FD. Compilation Error says that there is no matching catch blockAns:AC35.public static void main(String args[]){int a=10;int b=20;if(a=b)System.out.println("Not Equal");elseSystem.out.println("Equal");}

What will be the output?A. EqualB. Not EqualC. Compilation ErrorD. An Exception will occursAns:C//because if will return a number36. public static void main(String args[]){int t=0;while(1){if(t++<10)break;}}What will be the value of 't 'after the while loop ?A. 11B. 9C. 10D. Compilation ErrorE. An Exception will occursAns:D37. Which of the following will give correct declaration statement forfloat select 3A. float f= 1.0;B. float f= 3.222e+1;C. float f= -1;D. float f= 1;E. float f=1.0f;Ans:cde38. public static void main(String args[]){int t=0xffff1;int j=~t;System.out.println(j);}What will be the output?A. -1048562B. -10C. ExceptionD. Compilation ErrorAns:A//when you will use ~ then the +ive will become -ve39. package foo;

Page 10: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

class a{int c}class b{private int d}class c{public int e}which can class access all the variables in the limit foo?A. class aB. class bC. class cD. noneAns:B40.1.interface foo2. {3. int I=0;4. }5. class sreejith implements foo6. {7.public static void main(String args[])8.{sreejith s =new sreejith();9. int j=0;10.j=s.I;11.j=sreejith.I;12. j=foo.I;13. s.I=2;}}Where will compilation Fail?A.10B. 11C.12D.13E. No errorAns:D//variables inside the interface are by default public static final41. Which of the following will create an array that can be used for 50Strings? select 2A. char a[][]B. String a[]C. String[]a;D. String a[50];Ans: BC42. Where will be a 'is a ' relationship will occur select one?A. interface Personclass Employee implements PersonB. interface Shapeinterface Rectangle extends Shape

C. interface Componentclass Objects implement Component{Component [] Component;}Ans:B43. What will be the return type of the(short)10/10.2*2;A. shortB. intC. doubleD. floatE. Compilation ErrorAns:C44.Write the value for the following?6^3Ans: 545. What is the modifier is used for a variable in the class to beaccessed in subclass only?A. publicB. noneC. protectedD. privateAns:C46. What is the modifier is used to make a method to be overriddenin subclass?A. finalB. abstractC. staticD. volatileAns:B47. class sreejith{String s;public static void main(String args[]){sreejith ks=new sreejith();int j,i;i=ks.hai();j=ks.hello();System.out.println(i+" "+j);}int hai(){if (s==null)|| (s.length()==0))return 10;else return 0;}int hello()

Page 11: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

{if (s==null)| (s.length()==20))return 10;else return 0;}}what will be printed out?A. 10 10B. 10 nullC. 0 0D. Compilation ErrorE. An Exception in haiF. An Exception in helloAns:F48. Which are keywords in Java? Select 2A. transientB. trueC. sizeofD. implementE. synchronizeAns:AB49. 1. class sreejith2. {3. public static void main(String args[])4. {5. String s="hello";6. String s1="hello";7. System.out.println(s1);8. String s3=s1;9. s1=null;10. s=null;11. }Which line the garbage collector will invoke first?Ans: never invoke in this method50. To Read a File f=new File(C:\\hello.txt"); select all;new RandomAccessFile(f,"rw").readByte(?;FileInputStream fis=new FileInputStream(f);DataInputStream d=new DatainputStream(fis);d.readBytes(?FilterInputStream fis=new FilterInputStream(f,true);DataInputStream d=new

DatainputStream(fis);d.readBytes(?D. FileOutputStream fis=new FileOutputStream(f);DataOutputStream d=new DataOutputStream(fis);d.readBytes(?E. FilterOutputStream fis=new FilterOutputStream(f,true);DataOutputStream d=new DataOutputStream(fis);d.readBytes(?Ans:AD51.public static void main(String args[]){int j=10;int I=1;do{if (I++>--j)continue;}while(I<5);}what will be the value of I and j after the loop?Ans: I=5 J=652.What should you use to position a Button within an application frame sothat the vertical of the Button is only affected when you will resizethe window?A. FlowLayoutB. GridLayoutC. Center area of a BorderLayoutD. East or West of a BorderLayoutE. North or South of a BorderLayoutAns: D53.class c extends Frame{c(){setLayout(new BorderLayout());Panel p1,p2;p1=new Panel();p2=new Panel();p1.add(new Button("B1");p2.add(new Button("B2");

Page 12: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

add(new Button("B3"));setsize(300,300);setVisible(true);}public static void main(String args[]){c o = new c();}how will be buttons displayed?Ans: Only button 3 will displayed and will occupy entire frame54.public static void main(String a[]){StringBuffer s=new StringBuffer("Java");String c=new String("Java");Hello(s,c);System.out.println(s+c);}public static Hello(StringBuffer s, String c){s.append("C");c.repalce('A','D')}Write the Output?Ans: JavaCJava55.class Outer{class static Inner{}}How will you create an instance of static Inner Class? Select 2Inner a= new Inner();Outer o= new Outer();Outer.Inner a= new o.Inner();Outer.Inner a= new Outer.new Inner();Outer.Inner a= new Outer.Inner();Ans: BD56. . Write the range of int in values-2147483648 TO + 214748364757. which will contain the body of the threadrun()start()stop()main()init()

Ans: A57.Which of the following will give equal results?3/2 b.3<2 c. 3*4 d. 3<<2Ans: cd58.StringBuffer b=new StringBuffer();try{b.append("1");method();b.append("2");}catch(Exception a){b.append("3");}finally{b.append("4");}b.append("5");what will be the value of ' b' if the method throwsNullPointerException?Ans: 134559.if a method throws an ProtocolException(subclass of IOException) whichof the following can be used in declaring that methoda. public void method() throws Exceptionb. public void method() throw Exceptionc. public throws IOException void method()d. public void method() throws IOException.e. public void method() throws ProtocolException.Ans:DE60.What is the output when following code is run ?1. class ForLoop{2. public static void main(String args[]){3. int i=0,j=5;4. st: for(;;i++){5. for(;;j--){6. if(i>j)7. break st;8. }

Page 13: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

9. }10. System.out.println("i="+i+" j="+j);11. }12. }1. i=0 j=-12. i=1 j=03. i=0 j=14. i=1 j=-15. Compiler error at line 4.Ans : 161.What is the output when folllowing code is run?1. class OuterOne{2. class InnerOne extends OuterOne{}3. static void thisMethod(){4. Object o=(Object)new OuterOne();5. OuterOne foo=(OuterOne)o;6. }7. public static void main(String args[]){8. thisMethod();9. }10. }1. Will compile fine,but at runtime a ClassCastException is thrown2. Will compile and run fine3. Compiler error at line 44. Compiler error at line 5Ans: 262.public class Outer{//////}What should be inserted at ///// so that the code will compilefine?(Choose two)1. private class Inner{static int k;}2. static class Inner{static int k;}3. public class Inner{static int k;}4. public abstract class Inner{public abstract void method();}

Ans: 2,463.What will be the output when following code is run?1. class ThisClass{2. static void foo() throws Exception{3. throw new Exception();4. }5. public static void main(String args[]){6. try{7. foo();8. }catch(Exception e){9. System.exit(0);10. }11. finally{12. System.out.println("In finally");13. }14. }15. }1. Compiler error.2. Code will compile fine and when run prints In finally.3. Nothing will be printed.4. Runtime exception.Ans 264.import java.awt.*;class X extends Frame{X(){setLayout(new BorderLayout());setSize(600,600);Panel p=new Panel();Button b1=new Button("Button1");p.add(b1);Button b2=new Button("Button2");add(p,BorderLayout.NORTH);add(b2,BorderLayout.SOUTH);setVisible(true);}public static void main(String args[]){new X();}}How the components are displayed on the frame?1. Components will be of equal size.2. Button1 will be placed at top center and Button2 will occupyrest of the area.

Page 14: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

3. Button2 will be placed at top center of the frame and Button1will be placed at bottom center of the frame.4. Button2 will be placed at top center of the frame and Button1will be placed at bottom of the frame from left end to right end.5. Button1 will be placed at top center of the frame and Button2will be placed at bottom of the frame from left end to right end.Ans 565.File f=new File("aa.txt");Suppose this file exists in your directory.Which of the following can be used to write a line of text to theend of this file?1. RandomAccessFile f1=new RandomAccessFile(f,"r");2. RandomAccessFile f1=new RandomAccessFile(f,"a");3. RandomAccessFile f1=new RandomAccessFile(f,"rw");4. RandomAccessFile f1=new RandomAccessFile(f,"w");5. RandomAccessFile f1=new RandomAccessFile(f,"wr");Ans 366.What is the value of j when printed?class Foo{public static void main(String args[]){int x=4,j=0;switch(x){case 1:j++;case 2:j++;case 3:j++;case 4:j++;case 5:j++;break;default:j++;}System.out.println(j);}}1. 12. Compiler error

3. 64. 35. 2Ans 267.What will be the content of baz after the the following code is run?class A{public static void main(String args[]){String bar=new String("blue");String baz=new String("green");String var=new String("red");String c=baz;baz=var;bar=c;baz=bar;System.out.println(baz);}}1. red2. Compiler error3. blue4. null5. greenAns 568.import java.io.*;class Excep{static void method() throws Exception{throw new EOFException();}public static void main(String args[]){try{method();}catch(////){}}}Which of the following should be placed at //// so that the code willcompile without errors?1. IOException e2. EOFException e3. MalformedURLException e4. NullPointerException e5. Exception e6. FileNotFoundExceptionAns 569. What will be the output when the following code is run?

Page 15: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

1. class ThisClass{2. public static void main(String args[]){3. Object o=(Object)new ThisClass();4. Object s=new Object();5. if(o.equals(s))6. System.out.println("true");7. }8. }1. Prints true2. Nothing will be printed3. Compiler error at line 34. Compiler error at line 55. ClassCastException will be thrownAns 270.Which of the following interfaces that ArrayList directlyimplements?1. Set2. Map3. SortedSet4. List5. CollectionAns 471.What will be the output when following code runs?1. class C1{2. static int j=0;3. public void method(int a){4. j++;5. }6. }7. class Test extends C1{8. public int method(){9. return j++;10. }11.12. public void result(){13. method(j);14. System.out.println(j+method());15. }16. public static void main(String args[]){17. new Test().result();18. }19. }1. 32. 23. Compiler error at line 84. 1

5. 0Ans 272.What will be printed when following code runs?1. class Foo{2. static void change(String s){3. s=s.replace('j','l');4. }5.6. public static void main(String args[]){7. String s="java";8. change(s);9. System.out.println(s);10. }11. }1. Compiler error2. Will print lava3. Runtime exception4. Will print javaAns 2########74. 1.public static void main(String args[]){2. byte b=127;3. byte c=126;4. byte d=b-c;5. System.out.println(d);6.}a) Compilation succeeds and prints 1.b) Compilation succeeds but there will a Runtime Exception.c) Compilation error at line no 4.d) Compilation error at line no 5.Ans c75. Which is the valid identifier?a) 123_hellob) _12345c) !hellod) &sampleAns B76. Which two values are equal?a) 16<<2b) 16/3*2c) 16>>2d) 16<<<2e) 16>>>2f) 16/2Ans CE

Page 16: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

77. What is true about anonymous inner class?a) Anonymous inner class can be declared as public.b) Anonymous inner class can be declared as private.c) Anonymous inner class can be declared as static.d) Anonymous inner class can extend an abstract class.e) Anonymous inner class can be declared as protected.Ans D78. Which will return an int value very nearer to and not greater thanthe given double value?a) int a=(int)Math.max(double)b) int a=(int)Math.min(double)c) int a=(int)Math.ceil(double)d) int a=(int)Math.floor(double)e) int a=(int)Math.round(double)Ans d79. 1.import java.io.IOException;2.class Happy {3. public static void main(String args[]) {4. try {5. method1();6. }7. catch(IOException e) {8. System.out.println("Catch IOException");9. }10. catch(ArithmeticException e) {11. System.out.println("Catch ArithmeticException");12. }13. finally {14. System.out.println("Catch Finally");15. }16. }17.18. public void method1() throws IOException{19. throw new IOException();20. }21.}a) Compilation succeeds and prints "Catch IOException" and "Catch

Finally".b) Compilation succeeds but there will be a run time exception.c) Compilation error at line no.10d) Compilation error at line no.5e) Compilation error at line no.19Ans D80. Which method is used to construct and execute the thread?a) execute()b) run()c) build()d) start()Ans D81. import java.io.IOException;class Happy {public static void main(String args[]) {try {//code which throws an IOException}catch(IOException e) {System.out.println("Catch IOException");}catch(Exception e) {System.out.println("Catch Exception");}}}a) Compilation error complaining about class Excepion have not beenimported.b) Clean compilation but run time Exception is thrown.c) Execute fine.Ans C// Code runs wih out any problem82. switch(s) {default: System.out.println("Best Wishes");}Which datatype can 's' be?a) byteb) longc) floatd) doubleAns A83. public static void main(String

Page 17: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

args[]) {int i=1;int j=10;do{if(i>j)continue;j - -;} while(++i<6);System.out.println("i= "+i+" j= "+j);}What will be the output?a) i=4 , j=5b) i=5 , j=6c) i=5 , j=5d) i=4 , j=6e) i=6 , j=5Ans e84. 1.public static void main(String args[]) {2. Object o=new Float(12.4f);3. Object []oa=new Object[1];4. oa[0]=o;5. o=null;6. oa[0]=null;7. return 0;8.}Where will be the garbage collecter may invoke?a) just after line no.5b) just after line no.6c) just after line no.7d) never invokese) compilation errorAns B85. Which will be used to resize only the horizontal length?a) FlowLayoutb) GridBagLayoutc) BorderLayoutd) GridLayoute) both b and df) both c and bAns C86. Which of the following are valid declarations? (Select two)a) char c= ' \' 'b) char c= "cafe"c) char c= '\ucafe'd) char c= '\u01001'e) char c= '0x001'

Ans AC87. Which of the following will not directly cause a thread to stop?(Select two)a) notify()b) wait()c) exits synchronized coded) setPrioritye) InputSteam accessf) sleep()Ans AC88. What is the output?class Happy {public static void main(String args[]) {default: for(int i=0;i<10;i++) {mid: for(int j=0;j<5;j++) {System.out.println(j);}}}}Ans Error default is a key word89. What is the value of char ?a) -32768 - 32765b) 0 - 65536c) 0 - 32765d) -65536 - 65535e) 0 - 65535Ans C90. public class Happy {public static void main(String args[]) {int i=4;int j=2;methodA(i,j);System.out.println(i);}static public void methodA(int i,int j) {i<<=j;}}What will be the output ?a) compilation errorb) 16c) 64d) 4f) runtime exceptionAns D

Page 18: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

91. class Happy {public static returntype methodA(double d) {return (long)d;}public static void main(String args[]) {methodA(4.426);}}What should be the returntype in the methodA declaration?a) voidb) intc) longd) doublee) nothing neededAns C92. Which of the following is true of anonymous innerclass?a) Anonymous inner class can be declared as private,protected orpublic.b) Anonymous inner class can implement multiple interfaces.c) if not extended or implemented, an anonymous innerclass can becomeimmediate subclass of the outer class or implement an interface.d) if not extended or implemented, an anonymous inner class canbecome immediate subclass of outer class or implement mutiple interfaces.Ans C93. Which of the following are true about encapsulation ? (Select two)a) Direct access to variables.b) Access to variables through methods.c) keeping methods protected.d) use methods to access and modify the variable data.Ans BD94. 1.class Happy {2. public static void main(String args[]) {3. public class Sad {4. public void methodA() {

5. System.out.println("inside sad");6. }7. }8. System.out.println("inside happy");9. }10.}What will be the output ?a) compilation error at line no.3b) compilation error at line no.4c) compilation error at line no.5d) compilation succeeds but runtime exceptione) clean compile and give the output "inside happy"Ans A95. 1.class Happy {2. public static void main(String args[]) {3. int x=4;4. int y=2;5. if(x/y) {6. System.out.println(x+y);7. }8. }9.}What is the output?a) prints 6b) compilation error at line no.6c) compilation error at line no.5d) runtime exception occurse) prints 4Ans C96. How will you specify the access modifier for a method which shouldbe accessible only to the class in which it is defined?a) protectedb) staticc) privated) defaulte) finalf) abstractAns C97. class Happy {public static int main(String args[]) {Happy h=new Happy();h.methodA();}public void methodA() {

Page 19: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

System.out.println("Best Wishes");}}What will the output ?a)completime errorb)runtime excptionc)clean compile and output "Best Wishes"Ans C98. class Happy {class Sad extends Exception {}public void methodA() throws Sad {System.out.println("Best Wishes");}public void methodB() // what exception is to be thrown {methodA();}}a) Exceptionb) catch(Exception e)c) Throwabled) no code necessarye) comple time errorAns A99. Which type of the event is raised when enter key is pressed onjava.awt.Component?a) ClickEventb) ActionEventc) KeyEventd) ItemEvente) MouseEventans C100. What is true about constructors ? (Select two)a) They initialize all the member variablesb) They initialize all the instance variablesc) If there is no constructor , the compiler includes defaultconstructor.d) Compiler supplied constructor will invoke the default constructorof the super class.Ans CD101.what is the output when you compile and run this codeint i=0;

while (i--<0){System.out.pintln("value of i is"+ i);}System.out.pintln("the end");}}Ans the endWrite the answer102. Write the range of char0 -65535103. Write the range of int in values-2147483648- 2147483647//study this one104.what will be 's' after this code is runString s="hello";s.concat("mrs");s.toUpperCase();s+=" there";hello there105. which of these lines will compile if String s="example"a. s>>=2; b. int i = s.length();c. s+=3; d. char c= s[3]; e. s= s + "abcd";Ans b,c,e106. Under which conditions will a currently executing thread stopa. when an interrupted exception occursb. when a thread of higher priority is ready(becomes runnable)c. when the thread creates a new threadd. when the stop() method is called.ans: bd107.which of the following statements are truea. all the threads created in a class will come to an end at the sametime.b. you can stop a thread indefinitely if you wish to.c. you can start a thread only by extending the Thread class.d. multiple threads accessing same variable will lead to producingjunk(not the exact word)data.e.JVM exits after the main() thread is exited even if there might besome threads running.

Page 20: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

ans: bd108. derived1 and derived2 are two different classes extending classparent.what will happen to this codederived1 d1= new derived1();parent p = new parent();d1=(derived1)p;Ans: valid at compile and may fail at run time109. switch(x){case 1: System.out.println("case 1");case 2:case 3: System.out.println("case 2");break;default : System.out.println("case 3");}for what values of x will the output include case 3?Ans:1,2,3110. if(x>4){ System.out.println("case 1"); }elseif(x>9){ System.out.println("case 2"); }else{System.out.println("case 3");}what value(s) of x will cause case 3 printed in the outputa. less than zero. b. less than 4 c. between 4 and 9 d.10 andgreater e. noneAns B111.1. class A{2 public static void main(String[] args) String s1="Hi";3 String s2="There";45 s2+=s1;6 s1=null;7 s1=s2;8 System.out.println(s1);9 } }What is the earliest point where the memory space allocated to thestring in line 2(s1) can be released.(A) before line 6(B) before line 7(C) before line 8(D) before line 5

ans:A it will destroy the existing string and create new stringbecause strings are immutable112. if only the height of the component need be changed what would youusea.FowLayoutb.GridBagLayoutc.center of BorderLayoutd.north and south of BorderLayoute.east and west of BorderLayoutans: e113.which will contain the body of the threada.run() b.start() c.stop() d.main() e.init()ans:a114.what is the return type for the main() method which is the entrypoint for the classa.void b.int c.boolean d.stringans: a115.what is the return type for all the event listener methodsa.boolean b.depends on the listener c.void d.int e.event objectans:c116.what is the argument passed to the mouseListener method?ans:MouseEvent117.Which of the following will give equal results?3/2 b.3<2 c. 3*4 d. 3<<2ans:cd118.select valid keywordsa. sizeof b. NULL c. instanceof d. implements e. extendsans:de119.class A {String str;int x;int z;public A(String s , int a){str = s ;x = a ;}public A(int a,String s){///////}

Page 21: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

class B extends A{public B(String s, int a){super(s,a);}public B(String s, int a, int c) {////Az = c;}What code can be inserted at /////A so that it fully implementsthe existing code to initialize the values of x & str.ans:this(s,a) is the perfect ans not super(s,a);120.valid array declarationsa.int i[][]=new int[10,10];b.int i[10][10]=new int[][];c.int i [][]=new int[10][];d.int[]i[]=new int[10][10];e.int [][]i= new int[10][10];ans: cde121.if a method throws an ProtocolException(subclass of IOException)which of the following can be used in declaring that methoda. public void method() throws Exceptionb. public void method() throw Exceptionc. public throws IOException void method()d. public void method() throws IOException.e. public void method() throws ProtocolException.ans:you can use a base class or same class with declaration usingthrows statement122. if a classes should not be duplicated, ordered, and no specialsearch facility which of the following will you use.a.list b.set c.map d.collectionans:d123.if a class is ordered, duplicated which would u use.a.list b.set c.map d.collection e.enumeration.Ans A124.which of the following are valid array declaration for a string of

50 chars.a. char c[][]; b.String []s; c.String s[]; d.String s[50]; e.Objects[50];Ans:bc125.try{method();some code1}catch( IOException a){some code2}finally{some code3}some code4what will be excecuted if the method throws NullPointerException?some code 3 will execute126.1.//2 if(method()){3 //}4 else{5 //6 }7 //which line you insert the throw new Exception if the code should throwthe exception only if the method() returns true.Line 3127. if a variable should not be accessible in any way to code outsidethe class, how will u declare the variable?a. declare all variables as privateb. declare all methods as finalc. declare varicables as protectedAns:a128. what is valid declaration of a native method?public native void me(){};public void native me(){};c. public native void me();public void native me();Ans:c129. what keyword will you use so that the variable once declaredcannot be changed.

Page 22: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

130. what keyword will you use so that the wait() and notify() can beused.131.outer: for(int i=1;i<3;i++)inner: for(int j=1;j<3;j++){ if(j==2)break outer;System.out.println(i+" "+j);}what will this code give as the output.1 1132.how do you represent 7 in octal form using not more than 4characters.07133.what does the getId() method of events return?ID of the event134.what does >> and >>> represent?right shift and unsigned right shift135.which is possible parameter that can be passed into the construcorof a FilterInputStreama.File b.PrintStream c.FileOutputStreamd.FileInputStream e.RandomAccessFileAns D136. which of the following cannot be added to a containera.applet b.container c.menu item d.panel e.componentAns:c137. //public class first{......}which declarations are allowed in the //a.class second{}b.import java.util.*;c.package def.exam;d.public static final int i=10;e./* this is a test program */Ans:a,b,c,e138.how will u assign String s=one if u type the following in thecommand prompt for Animal classjava Animal one two threepublic class Animal{public static void main(String[]args)

{}}a.s=args[0] b.s=args[1] c.s=args[2] d.s=args[3] e.s=args[4]Ans:a139. String s=null.which of the following code not throwNullPointerExceptiona. s!=null && s.length()=0 b. s!=null & s.length()=0c s==null || s.length()=0 d s==null | s.length()=0Ans:a,c140. What is true about Garbage collector :a. programmer can create and delete memoryb. is your program guaranteed that will run without memory leaksc. programmer can make variables eligible for garbage collectionAns:c141.valid Inner class declaration select 2a. private class c b. new simpleInterface() {c. new somplexInterface(x){..} d. private final abstract class x{e. new simpleclass(x) implements simpleinterface {Ans:a,b142. what is true about inner class select 2a. inner class can be instantiated only in it's enclosing classb. they can be accessed only within the enclosing classc. they cannot implement interfaced. They can extend a classe. they can access final varaibles within their declaration scopeAns:d,e143.Which of the following will describe a perfect encapsulation?select 2a. making all method private b. making all variables privatec. making class final d. making methods to publice. making all variables private and

Page 23: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

access it through methodsAns:be144. what type of variables should be used for the following select allClass Employee is a person, has a vector to store something,has a number of dependents, has a date attributevector b. int c. person d. object e. DateAns: a,b,d145.public class base{public int b;public float method(float f) {int i;}}public class sub extends base {private float f1;public static void main (String args[]) {base b=new base();float g;int j;//}} what is valid at //a. g=f1; b. g=b.f; c. j=b.i; d. b.method(10.0f) e. g=b.bAns:de146. class base{long l=10public void main(String args[]){base x, y,z;long l=10;x=new base();y=new base();z=y }}which will return truea. x==y b. l==x c. y==z d. l==10.0Ans:c,d147. public class base {String name;String value;public base(String n,String m) {name=n;value=m; }public String toString() {return name;}}public class sub extends base {public String toString() {return name+":"+value;}public sub(String n, String m){super(n,m); }

public static void main(String args[]) {base b=new base("first","1st");base b1=new sub("second","2nd");System.out.println(b.toString()+b1.toString());}}what will be the outputa. compilation errorb. first second : 2ndc. second : 2 second : 2ndAns:b148. int i[] =new int[10]what is the value of i[5]149. what is the output when you compile and run the following code?public class Sup{static StringBuffer sb1=new StringBuffer("Hello");static StringBuffer sb2=new StringBuffer("Hello");public static void main(String args[]){aMethod(sb1,sb2);System.out.println("sb1 is"+sb"\n"+"sb2 is"+sb2);}public static aMethod(StringBuffer sb1,StringBuffer sb2){sb2.append(" there");sb1=sb2;}}(a) compilation error(b) invalid argument to System.out.println(c) compile and output issb1 is Hello sb2 is Hello there(d) compile and output issb1 is Hello there sb2 is Hello(e) compile and output issb1 is Hello there sb2 is Hello thereAns:chere you will have two pointer which is pointing to hello( sb1, and amethods local variable sb1 ) you are changing the reference of localsb1 so it will not affect the orginal one in case of sb2 both local andoriginal are pointing to same as in the case of sb1 but here you are

Page 24: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

changing the contents so it will affect the original.150. class Happy {public static void main(String args[]) {float [] [] f1={ {1.2f,2.3f},{4.5f,5.6f}};Object oo=f1;f1[1] =oo;System.out.println("Best Wishes "+f1[1] );}}What will the output ?a) {4.5,5.6}b) 4.5c) compilation error in line no.5d) exceptionAns C151.outer:for(i=1;i<3;i++){ for(j=1;j<3;j++){if(j==2)continue;System.out.println("i is"+ i " j is" + j);}}152)polygon is Drawable and has information vertices stored in vector,a color and fill flag(which is true or false)Which of the following felds you will include in class Polygon.Select most appropriate.[a] vector [b] Color [c] boolean [d] Boolean [e] Object [f] StringAns:a,b,c153.What is the valid declaration of native method[a] public native void method(); [b] public void native method();[c] public void native method(){} [d] public native void method(){}Ans:a154. class Happy {static StringBuffer sb1=new StringBuffer("A");static StringBuffer sb2=new StringBuffer("B");public static void main(String args[])

{Happy h=new Happy();h.methodA(sb1,sb2);System.out.println(sb1+" , "+sb2);}public void methodA(StringBuffer x,StringBuffer y) {y.append(x);x=y;}}What will the output ?a) BA,BAb) A,ABc) BA,ABd) A,BAe) A,Af) compilation errorAns D155.1Class X {2 Frame f = new Frame(); String s;3 Button b=new Button("Click me");4 Add(b);5 b.addActionListener(new ActionListener(){6public void actionPerformed(ActionEvent ae){5 s= "message";6System.out.println("message is "+s);7}})}What happens when the button ("click me" ) is pressed.[a] compilation error at line 1 [b] prints message is click me.[c] compilation error at line 5 [d] print the message is messageAns:D156. class Happy {String s="Hello";public static void main(String args[]) {Happy h=new Happy();h.methodA(s);System.out.println(h.s);}public static void methodA(String s) {s.replace('a','e');

Page 25: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

s+=" World !!!" ;}}What will the output ?a) compile error because string is not static.b) prints "Hello World !!!"c) prints "Hello"d) prints " World !!!"e) Runtime exception occursAns A157. An application consists of a set of user interfaces & the variousoperations are to be performed based on the various user invokedevents. Which of the following are true for the above application(a) Extending Adapter classes is not suitable(b) Some listener interface must be implemented(c) If a particular event listener is implemented only the methods ofinterest to us need to be implemented(d) Multiple event listeners can be added to a single component(e) The order in which the events are processed is the order in whichthe listeners are addedAns:a,d158. class Happy {public int getLength() {System.out.println("int version");}}class Life extends Happy {public long getLength() {System.out.println("long version");}public static void main(String args[]) {Happy e=new Life();e.getLength();}}Which method gets executed?a) int versionb) long versionc) compile time error

d) run time exceptione) clean compile but no outputAns C160. class Happy {public static void main(String args[]) {int i=1;int j=i++;if ((i == (++j) ) & ( (i++) = = j ) {i+=j;}}}What will the value of i after this code execution ?a) 4b) 5c) 2d) 3e) compilation errorAns B161. class Happy extends Frame{Happy() {setLayout("FlowLayout");add(new Button("hello1");add(new Button("hello2");pack();show();}public static void main(String args[]) {Happy h=new Happy();}}a) only one button will be shown with label "hello2".b) only one button will be shown with label "hello1".c) two buttons will be shown .d) compilation error.Ans D162. class Happy implements Runnable {private int x;private int y;public void run() {//some code}public static void main(String args[]) {

Page 26: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

Happy h=new Happy();new Thread(h).start();new Thread(h).start();}void setX(int i) {x=i;}void setY(int j) {y=j;}synchronized void setXY(int i) {setX(i);setY(i);}synchronized boolean check() {return x!=y;}}Select a true statement from the following.a) check() never returns true.b) multiple threads accessing setX(),setY() can result in check()returning true.c) multiple threads accessing setXY() can result in check()returning true.d) compilation error because there is no start() .Ans B163) What will you write in the palce of 'xxx' to make instantce ofinner classclass OuterOne {class InnerOne {}}class Test {OuterOne o=new OuterOne();//write code to create an instance of the inner class}a)o.InnerOne in = o.new InnerOne();b)InnerOne in=new o.new InnerOne();c)OuterOne.InnerOne in =new o. InnerOne();d)OuterOne.InnerOne in = o.new InnerOne();Ans D164)Examine the code below and

select the best answerclass OuterOne {static class InerOne{}}a)we can't make instantce of innerclass outside class OuterOneb) ' InnerOne in=new Inner()' will make instance of inner class inanother classc) ' OuterOne.InnerOne in=new OuterOne.Inner()'d) ' InnerOne in=new OuterOne().new Inner()' will make instance ofinner class in another classAns C165)1) class Foo {2) public static void main(String args[]) {3) int s=10;4) s>>=10;5) System.out.println("s=" +s);6) }7) }a) compileerror at line 4b) clean compile but exception at runtimec) 0d) 1Ans C166)1) class Foo {2) public String toString(){3) return ""+3;4) }}5) class FooTest extends Foo {6) public static void main(String as[]){7) FooTest f=new FooTest ();8) System.out.println(f);9) }10) public String toString(){11) return super.toString()+4;12) }13) }a) compile errorb) clean compile but exception at runtimec) 43

Page 27: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

d)34e) 7Ans 34167) write outputint i=0int j=5out: for( ; ; i++)for( ; ; j--)if( i > j)break out;System.out.println(i+" " +j)AnS 0 -1168) what will get printed1) class Foo {2) public static void main(string as []) {3) int j=1;4) int x=4;5) switch(x) {6) case 1: j++;7) case 2: j++;8) case 3: j++;9) case 4: j++;10) case 5: j++;11) default : j++;12) }13) System.out.println(x+j);14) }15) }Ans 8169) which of the following can put in the place of xxx to indicatemyMethod may throw an exceptionclass Foo {void myMethod()//xxxxx {......}}a)Exceptionb)Errorc)RuntimeExceptiond)Objecte)Eventf)ThrowableAns A170) which is true about the following code1) class Foo extends Frame {2) Foo() {3) Panel p=new Panel();4) p.add(new Button("One"));5) add("North",p);

6) add("South",new Button("Two"));7) pack();8) setVisible(true);9) }10) public static void main(String args[]) {11) Foo f=new Foo();12) }13) }a)when the frame is resized both button's size is affectedb)when the frame is resized both button's size is unaffectedc)button "Two" get resizedd)button "Owo" get resizedAns C171)1)class Foo {2) static void main(String as[]) {3) unsigned int a=1,b=2,c;4) c=a+b;5) System.out.println("c=" +c);6) }7) }a)compiler errorb)clean compile buy exception at runtimec)will print 3Ans A172)you want to check whether a directory exists in 'c:\' named 'sam'a) File f=new File("\\","sam")RandomAccessFile raf=new RandomAccessFile(f)if(raf.Directory())System.out.println("True");b) File f=new File("\\","sam")FileOutputStream fos=new FileOutputStream(f)if(fos.Directory())System.out.println("True");c) File f=new File("\\","sam")if(f.exists())if(fos.Directory())System.out.println("True");Ans C173)Boolean b[]=new Boolean[10]if(b[1])

Page 28: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

System.out.println("true");elseSystem.out.println("false");a)copile errorb)clean compile buy exception at runtimec)will print "true"d)will print "false"Ans A174)byte b=127;byte c=126;byte a=c-b;a)compile errorb)clean compile buy exception at runtimec)clean compile and runAns A175)wht will happen if you try to compile and run the following code1)class Father {2) int var1=10;3) void amethod() {4) System.out.println("father method ");5) }6)}7) class Son extends Father {8) int var1=20;9) void amethod() {10) System.out.println("father is over ridden ");11) }12) void bmethod() {13) System.out.println("son's method ");14) }15) public static void main(String as[]) {16) Father f=new Son();17) System.out.println(f.var1);18) f.bmethod();19) f.amethod();20) }21) }a)compile errorb)clean compile but may throw exceptionc)will print 10,son's method,father is

overiddend)will print 20,son's method,father is overiddene)will print 10,son's method,father methodAns A176)RandomAccessFile raf=new RandomAccessFile("sam","rw");raf.close();a)compile errorb)clean compile but may throw exception if a file names 'sam' nottherec)a file of 0 length is createdd)if a file already exists then no change is occuredAns C#177class Foo {4 public static void main(String args[]) {5 Object o=new Object();6 Object oa[]=new Object[1];7 o=4;8 oa[0]=4;9 o=null;10 oa=null;11 return oa[];}};At which line garbage collector will invokea)after line 8b)after line 9c)after line 10d)will never invokeAns b#178class Foo {public static void main(String args[]) {int i=10;int j=0;tp:for(;;i--){for(;;j++){if(i>j) break tp;}}System.out.println(i+" "+j);

Page 29: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

}};What will be the output ?a)10,0b)10,1c)10,-1d)9,-1Ans A#179class Foo{public int getLength(int a,int b,float c){for(int i=0;i<100;i++){if(i==j)continue;}}};class Bar extends Foo {public void getLength(int a,int b,float c){for(int i=0;i<100;i++){if(i==j)continue;}};What will be result in compiling an running ?a)0 to 99b)0 to 100c)Exceptiond)compile time errorAns D#180class Foo{static final StringBuffer sb1=new StringBuffer();static final StringBuffer sb2=new StringBuffer();public static void main(String args[]) {new Thread(){public void run(){synchronized(sb1){sb1.append("A");sb2.append("B");}}}.start();new Thread(){public void run(){synchronized(sb1){

sb1.append("C");sb2.append("D");}}}.start();System.out.println (sb1+" "+sb2); };what will be the output?//options given for the above program were confusing .// Here you are having three chances// main will finish before starting threads//main will finish middle of one thread// main will finish after one thread//main will finish in middle of the second thread//main will finish after the second thread//##important thing is we can't predict which thread is going to startfirst#181class Foo{public static int main(String args[]) {int i=0;int j=0;tp:for(;i=i+1;){for(;;j--){if(i>j) break tp;}}System.out.println(i+" "+j);}};What will be the outputa)0,0b)0,1c)0,-1d)1,0e)compile time errord)ExceptionAns E#182class Foo{public static void main(String args[]) {public void aMethod(){int x=4;int y=2;

Page 30: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

int a=2;if(a=(x/y)){System.out.println("x :"+x+"y :"+y);}}};What will be the output ?(options will be given)Ans Compilation Error#183class X implements Runnable {public static void main(String args[]) {//what should be inserted here ?}}which of the following line of code is suitable to start a threada)Thread t=new Thread(X);b)Thread t=new Thread(X);t.start();c)X run=new X();Thread t=new Thread(run);d)Thread t=new Thread();x.run();Ans C#184class Foo {public static void main(String args[]) {try{return;}finally{System.out.println("finally");}}};a)nothing will be printed.b)finally will be printed .c)an exception is thrown .d)Runtime exception is thrown .Ans B#185What is true about anonymous inner classes ?a)it can implement more than one interfacesb)it can implement only an interfacec) it can only extend an abstract class

d) it can extend any classE) it can implement extend a class and implement an interface.Ans D#186What is true about static class ?a)static class need no instance to access methods or variablesb)static class need an instance to access methods or variablesC)it is not possible to decalre first level class as static#187class Foo {public static void main(String args[]) {int i=0;int j=0;for:for(;;i++){for(;;j--){if(i>j)break for;}}System.out.println(i+" "+j);}};What will be the output ?a)0,0b)0,1c)0,-1d)1,0E)Compilation errorf)ExceptionAns E#188Which one of the following is used to read ascii codes from a file ?a)FileReaderb)InputStreamc)characteArrayReaderd)InputStreamReadere)OutputStreamReaderAns D#189Which one of the following methods will not allow to overridea)public void aMehod(int a);b)final void aMethod(){ };c)static final aMethod(){ };

Page 31: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

d)final abstract void aMethod(){ };c)public void final aMethod(){ };Ans B#190Which one of the following will be equal results ?a)3*2b)3*8c)3<<3d)3*2^3e)3<<<2Ans BC#191Which one of the following is used to start a Thread ?options will be givenAns: Start();#192Which of the following are true about static inner classes ?a)can acces all method variables in the enclosing scopeb)can acces all instance variables in the enclosing scopec)can access all static variables in the enclosing scopeAns C1931) class hai{public static void main(int c) {Integer a[]=new Integer[4];int I= 1;System.out.println(a[I]); }}}What will be printed if you will execute using java hai?ExceptionWill print trueWill print falseWill print nullAns Exception no method found main#194class Super {};class Foo extends Super {public static void aMethod(Foo o){Super a=o;System.out.println("Happy");}public static void main(String args[])

{]Foo f=new Foo();aMethod(f);}};a)compilation errorb)class cast exceptionc)clean compile and executiond)clean compile, runtime errorAns C195. which of the following is valid?public final hai();public static final abstract void hai();final public void hai();public void final hai();Ans CD196 What is true about anonymous inner class select 3It can implement only one interfaceit can implement multiple interfacesit should be declared inside the methodIn some cases it can call constructor with parametersAns ACD197. What is a feature of encapsulationDirect access to variablesMethods are publicMethods are protectedD. no direct access to variablesAns D198. Which is/are the correct form of overriding for the methodpublic int Sree()public void Sree()protected int Sree()c. public int Sree()final int Sree()public abstract int Sree()Ans C199. which are correct form of overloading for the method public intSree()public void Sree()B. int Sree(int a,int b)C. public int Sree(int a)D. void Sree(int d, String s)Ans BCD

Page 32: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

200. Predict the outputpublic class test {public static void main(String args[]) {int i=0;int j=0;outer: for(i = 0; i < 3; i++) {for(j = 3; j >= 0; j--) {if(i == j)break outer;}}System.out.println(i + " " + j);}Ans 0 0201. 1.public static void main(String args[]){2. byte b=127;3. char c=126;4. char d=b-c;5. System.out.println(d);6.}a) Compilation succeeds and prints 1.b) Compilation succeeds but there will a Runtime Exception.c) Compilation error at line no 4.d) Compilation error at line no 5.Ans C202. Which is the valid identifier?a) 1_1db) _h_c) @examd) ^javaAns B203. Which two values are equal?a) 12<<2b) 12/3*2c) 12>>2d) 12<<<2e) 12>>>2f) 12/2Ans CE204. What is not true about anonymous inner class?a) Anonymous inner class can not be declared as public.b) Anonymous inner class can not be declared as private.c) Anonymous inner class can not be

declared as static.d) Anonymous inner class can not extend an abstract class.e) Anonymous inner class can not be declared as protected.Ans D205. Which of the following will return an long value?a) Math.max(double)b) Math.min(double)c) Math.ceil(double)d) Math.floor(double)e) Math.round(double)Ans E206. 1.import java.io.IOException;2.class Happy {3. public static void main(String args[]) {4. try {5. method1();6. }7. catch(IOException e) {8. System.out.println("Catch IOException");9. }10. catch(ArithmeticException e) {11. System.out.println("Catch ArithmeticException");12. }13. finally {14. System.out.println("Catch Finally");15. }16. }17.18. public void method1() throws IOException{19. throw new IOException();20. }21.}a) Compilation succeeds and prints "Catch IOException" and "CatchFinally".b) Compilation succeeds but there will be a run time exception.c) Compilation error at line no.10d) Compilation error at line no.5e) Compilation error at line no.19Ans D207. Which method is used to

Page 33: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

construct and execute the thread?a) execute()b) run()c) build()d) start()Ans D208. import java.io.EOFException;class Happy {public static void main(String args[]) {try {//code which throws an EOFException}catch(EOFException e) {System.out.println("Catch EOFException");}catch(IOException e) {System.out.println("Catch IOException");}}}a) Compilation error complaining about class IOExcepion have not beenimported.b) Clean compilation but run time Exception is thrown saying thatIOExceptions is never thrownc) Execute fine.Ans C209. switch(s) {default: System.out.println("Best Wishes");}Which datatype can 's' be?a) charb) longc) floatd) doubleAns A210. public static void main(String args[]) {int i=1;int j=10;do{if(i>j)continue;

j --;} while(++i<6);System.out.println("i= "+i+" j= "+j);}What will be the output?a) i=4 , j=5b) i=5 , j=6c) i=5 , j=5d) i=4 , j=6e) i=6 , j=5Ans E211. 1.public static void main(String args[]) {2. Object o=new Float(12.4f);3. Object []oa=new Object[1];4. oa[0]=o;5. o=null;6. oa[0]=null;7. return o;8.}Where will be the garbage collecter may invoke?a) just after line no.5b) just after line no.6c) just after line no.7d) never invokese) compilation errorAns B212. Which will be used to resize only the horizontal length?a) FlowLayoutb) GridBagLayoutc) BorderLayoutd) GridLayoute) both b and df) both c and bAns C213. Which of the following are valid declarations? (Select two)a) char c= ' \' 'b) char c= "cafe"c) char c= '\ucafe'd) char c= '\u01001'e) char c= '0x001'Ans AC214. Which of the following will not directly cause a thread to stop?(Select two)a) notify()b) wait()

Page 34: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

c) exits synchronized coded) setPrioritye) InputSteam accessf) sleep()Ans AC215. What is the output?class Happy {public static void main(String args[]) {default: for(int i=0;i<10;i++) {mid: for(int j=0;j<5;j++) {System.out.println(j);}}}}Ans Compilation Error default is a keyword216. What is the value of char ?a) -32768 - 32765b) 0 - 65536c) 0 - 32765d) -65536 - 65535e) 0 - 65535Ans E217. public class Happy {public static void main(String args[]) {int i=4;int j=2;methodA(i,j);System.out.println(i);}static public void methodA(int i,int j) {i<<=j;}}What will be the output ?a) compilation errorb) 16c) 64d) 4f) runtime exceptionAns A218. class Happy {public static returntype methodA(double d) {return (long)d;}

public static void main(String args[]) {methodA(4.426);}}What should be the returntype in the methodA declaration?a) voidb) intc) longd) doublee) nothing neededAns C219. Which of the following are true of anonymous inner class?a) Anonymous inner class can be declared as private , protected orpublic.b) Anonymous inner class can implement multiple interfaces.c) if not extended or implemented, an anonymous inner class canbecome immediate subclass of the outer class or implement an interface.d) if not extended or implemented, an anonymous inner class canbecome immediate subclass of outer class or implement multiple interfaces.Ans C220. Which of the following are true about encapsulation ? (Select two)a) Direct access to variables.b) Access to variables through methods.c) keeping methods protected.d) use methods to access and modify the variable data.Ans BD221. 1.class Happy {2. public static void main(String args[]) {3. public class Sad {4. public void methodA() {5. System.out.println("inside sad");6. }7. }8. System.out.println("inside happy");

Page 35: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

9. }10.}What will be the output ?a) compilation error at line no.3b) compilation error at line no.4c) compilation error at line no.5d) compilation succeeds but runtime exceptione) clean compile and give the output "inside happy"Ans A // if there is no public at line 3 then clean compile andexecution222. 1.class Happy {2. public static void main(String args[]) {3. int x=4;4. int y=2;5. if(x/y==2) {6. System.out.println(x+y);7. }8. }9.}What is the output?a) prints 6b) compilation error at line no.6c) compilation error at line no.5d) runtime exception occurse) prints 4Ans A223. How will you specify the access modifier for a method whichshould beaccessible only to the class in which it is defined?a) protectedb) staticc) privated) defaulte) finalf) abstractAns C224. class Happy {public static int main(String args[]) {Happy h=new Happy();methodA();}public void methodA() {System.out.println("Best Wishes");}

}What will the output ?a)completime errorb)runtime excptionc)clean compile and output "Best Wishes"Ans A225. class Happy {class Sad extends Exception {}public void methodA() throws Sad {System.out.println("Best Wishes");}public void methodB() // what exception is to be thrown {methodA();}}a) Exceptionb) catch(Exception e)c) Throwabled) no code necessarye) comple time errorAns A226 Which type of the event is raised when enter key is pressed onjava.awt.Component?a) ClickEventb) ActionEventc) KeyEventd) ItemEvente) MouseEventAns C227. What is true about constructors ? (Select two)a) They initialize all the member variablesb) They initialize all the instance variablesc) If there is no constructor , the compiler includes defaultconstructor.Compiler supplied constructor will invoke the default constructor oftheSuper class.Ans CD228. class Happy {public static void main(String args[]) {float [] [] f1={ {1.2f,2.3f},

Page 36: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

{4.5f,5.6f}};Object oo=f1;f1[1] =oo;System.out.println("Best Wishes "+f1[1] );}}What will the output ?a) {4.5,5.6}b) 4.5c) compilation error in line no.5d) exceptionAns C229. class Happy {static StringBuffer sb1=new StringBuffer("A");static StringBuffer sb2=new StringBuffer("B");public static void main(String args[]) {Happy h=new Happy();h.methodA(sb1,sb2);System.out.println(sb1+" , "+sb2);}public void methodA(StringBuffer x,StringBuffer y) {y.append(x);x=y;}}What will the output ?a) BA,BAb) A,ABc) BA,ABd) A,BAe) A,Af) compilation errorAns C230. class Happy {String s="Hello";public static void main(String args[]) {Happy h=new Happy();h.methodA(s);System.out.println(h.s);}public void methodA(String s) {s.replace('a','e');s+=" World !!!" ;}

}What will the output ?a) compile error because string is not static.b) prints "Hello World !!!"c) prints "Hello"d) prints " World !!!"e) Runtime exception occursAns A231. class Happy {public int getLength() {System.out.println("int version");}}class Life extends Happy {public long getLength() {System.out.println("long version");}public static void main(String args[]) {Happy e=new Life();e.getLength();}}Which method gets executed?a) int versionb) long versionc) compile time errord) run time exceptione) clean compile but no outputAns C232. class Happy {public static void main(String args[]) {int i=1;int j=i++;if ((i == (++j) ) & ( (i++) = = j ) {i+=j;}}}What will the value of i after this code execution ?a) 4b) 5c) 2d) 3e) compilation errorAns B233. Which of the following will

Page 37: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

directly stop the execution of aThread? (Choose two)a) wait()b) notify()c) notifyall()d) exits synchronized codee) setPriorityAns D234. class Happy extends Frame {Happy() {Panel p = new Panel();Button b1 = new Button(“North?;p.add(b1);add (p,BorderLayout.NORTH);Button b2 = new Button(“SOUTH?;add(b2,BorderLayout.SOUTH);setSize(300,300);setVisible(true);}public static void main(String args[]) {Happy h = new Happy();h.pack();}}a)b)c)d) Runtime Exceptione) Compilation ErrorAns :the North button will be in north but it will not occupy the fullplace the secon button in south will occupy full place235. class Happy extends Thread {final StringBuffer sb1 = new StringBuffer();final StringBuffer sb2 = new StringBuffer();public static void main(String args[]) {final Happy h=new Happy();new Thread() {public void run()throws Exception {synchronized(this) {h.sb1.append(“A?;h.sb2.append(“B?;System.out.println(h.sb1);System.out.println(h.sb2);}

}}.start();new Thread() {public void run() {synchronized(this) {h.sb1.append(“D?;h.sb2.append(“C?;System.out.println(h.sb2);System.out.println(h.sb1);}}}.start();}}What may be the output of this code ?(Choose two)a) ABBCADb) ABCBCADc) CDADACBd) CDDACBe) Output non-deterministic because of the chance of ‘deadlock?f) Output determined due to the underlying platform.Ans BC //out put is non deterministic because here threads are lockingdifferent objects####Same type of question with little changeclass Happy extends Thread {final StringBuffer sb1 = new StringBuffer();final StringBuffer sb2 = new StringBuffer();public static void main(String args[]) {final Happy h=new Happy();new Thread() {public void run()throws Exception {synchronized(h.sb1) {h.sb1.append(“A?;h.sb2.append(“B?;System.out.println(h.sb1);System.out.println(h.sb2);}}}.start();new Thread() {public void run() {synchronized(h.sb1) {

Page 38: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

h.sb1.append(“D?;h.sb2.append(“C?;System.out.println(h.sb2);System.out.println(h.sb1);}}}.start();}}What may be the output of this code ?(Choose two)a) ABBCADb) ABCBCADc) CDADACBd) CDDACBe) Output non-deterministic because of the chance of ‘deadlock?f) Output determined due to the underlying platform.Ans A,D236. class Happy {static String str =”Hello?Public static void main(String args[]) {String s = new String();s.change(str);System..out.println(str);}public void change(String s) {s +=?World?}}a) prints Hello Worldb) prints Helloc) compilation error because change is not staticd) runtime exceptionAns C237. A method is to be accessed in same package without instances ofthe class.a) public void method1();b) protected void method1();c) static void method1();d) void method1();Ans C238. Which is/are the valid identifiers ?a) 2intb) name-lst

c) _123d) 1dir_liste) second-1Ans C239. Classone.java1.2.package cmd.abc.pkg1;3.public class Classone {4. char getVar() {5. System.out.println(“Hello?;6. return ‘a?7. }8.}Classtest.java1.package cmd.abd.pkg2;2.import cmd.abc.pkg1.Classone;3.class Classtest extends Classone {4. public static void main(String args[]) {5. char a=(new Classone()).getVar();6. char b=(new Classtest()).getVar();7. System.out.println(“Hello?;8. }9.}a) Compilation error at line no. 6 in Classone.javab) Compilation error at line no. 5 in Classtest.javac) Compilation error at line no. 6 in Classtest.javad) Compilation succeeds but there is a Runtime exception due toinstance of the class can not be assigned to a char datatype.Ans C //because getvar is declared as friend240. 1. abstract class Happy {2. abstract float getFloat();3.}4.class Life extends Happy {5. private float getFloat(){}6. public static void main(String args[]) {7. System.out.println(“Best Wishes?;8. }9.}a) Compilation errot at line no.4b) Compilation errot at line no.5c) Compilation errot at line no.2d) Compilation succeeds but runtime

Page 39: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

exception occurs.e) Clean compilatin and executes finely.Ans B //cannot be overriden as private241. Which is the true statement ?a) Errors are subclasses of RuntimeExceptions.b) No Exceptions are subclasses of Errors.c) Errors should be catched and handled.d) RuntimeExceptions cannot be catched and handled.Ans D242. class Happy {protected void setVal(float f) {// some code}}class Life extends Happy {// Which overriding methods can be succeessfully placed here ?}(Select two)a) protected float setVal(float f) { …}b) public void setVal(float f) { …}c) protected void setVal(float f,int i) { …}d) protected final void setVal(float f) { …}e) public float setVal(float f) { …}Ans B,D243.class Happy {public byte methodA() {return 4;}}class Life extends Happy {public short methodA() {return 2;}public static void main(String args[]) {short s;Life a = new Life();s = a.methodA();System.out.println(s);}

}What is the output ?a) prints 2.b) prints 4.c) prints 0.d) Compilation error.e) Runtime exception.Ans D244.An Interface is an interface.An Adapter0 is a class with zero argument constructor.AnAdapter1 is a class without zero argument constructor but with an intargument constructor.Which is the valid declaration?a) AnAdapter0 aa=new AnAdapter0();AnAdapter1 bb=new AnAdapter1();b) AnAdapter0 aa=new AnAdapter0();AnAdapter1 bb=new AnInterface();c) AnAdapter1 aa=new AnAdapter1(5);AnInterface bb=new AnInterface();d) AnAdapter0 aa=new AnAdapter0();AnAdapter1 bb=new AnAdapter1(5);Ans D245.public abstract class Happy {abstract void methodA();abstract void methodB() {System.out.println(“Best Wishes?;}}Which three changes (made independently) allow the code to compilesucceessfully ?a) Remove the ‘abstract?keyword from methodB.b) replace ??with { …} in methodA .c) remove the methodB().d) replace the methodB definition (ie, {…}) with ?”and Replace theclass declaration with interface declaration in line no.1.e) No need to do anyting.f) Remove the ‘abstract?keyword

Page 40: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

from line no.1.Ans ACD246. Which of the following two declarations used to read a filecalled ‘Test.txt?a) RandomAcceesFile raf=new RandomAcceesFile(“Test.txt?;b) InputStream is = new FileInputStream(“Test.txt?;c) InputStream is = newDataInputStream(FileInputStream(“Test.txt?true));d) FileInputStream fis = new FileInputStream(new File(“Test.txt?);e) FileoutputStream fos = new FileoutputStream(new File(“Test.txt?);f) OutputStream os = new FileoutputStream(new File(“Test.txt?false));Ans BD247. Import java.io.*;class Happy {public static void main(String args[]) {try {File f = new File(“Test.txt?;OutputStream o=new FileOutputStream(f);}catch(IOException e) { }}}What happens when this code compiles and run?a) Compilation error.b) The code compiles and runs successfully but no file is created.c) A file with zero length is created.d) The code compiles but there will be a RuntimeException because thereis no matching constructor for the FileInputStream.Ans C248. class Happy extends Thread {final static StringBuffer sb1 = new StringBuffer();final static StringBuffer sb2 = new StringBuffer();

public static void main(String args[]) {new Thread() {public void run() {synchronized(sb1) {sb1.append(“A?;sb2.append(“B?;System.out.println(sb1);System.out.println(sb2);}}}.start();new Thread() {public void run() {synchronized(sb2) {sb1.append(“D?;sb2.append(“C?;System.out.println(sb2);System.out.println(sb1);}}}.start();}}What may be the output of this code ?(Choose two)a) ABBCADb) ABCBADc) CDDACBd) Output non-deterministic because of the chance of ‘deadlock?e) Output determined due to the underlying platform.Ans AD249. class Happy {public static void main(String args[]) {int i=3;int j=5;if(i++ > (--j)) & ((++j) < 10)j+=5;System.out.println (“j is ?j+? i is ?i);}}What will the output?a) j is 10 and i is 4b) j is 5 and i is 4c) j is 10 and i is 3d) j is 5 and i is 3g) compilation error

Page 41: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

h) runtime exceptionAns B250. class Happy {public static void main(String args[]) {float f=4.2f;Float g=new Float(4.2f);Double d=new Double(4.2);}}Which will return true (or will not show any compilation error orRuntimeException)?(Select two)a) f==gb) g==gc) g.equals(f)d) d.equals(d)e) d.equals(f)Ans BD251. class Happy implements Runnable {private int x;private int y;public void run() {// what code should be placed here ?}public static void main(String args[]) {Happy h = new Happy();new Thread(h).start();new Thread(h).start();}public void setX(int i) {x = i;}public void setY(int j) {y = j;}synchronized public void setXY(int i) {setX(i);setY(i);}synchronized public boolean check() {return x != y;}}a) check() never returns true.

b) multiple threads accessing setX(),setY() can result in check()returning true.c) multiple threads accessing setXY() can result in check()returning true.d) compilation error because there is no start() .Ans B252. How to append to file “Test.txt? (Select two)a) FileOutputStream fis = new FileOutputStream ( “Test.txt? true);b) OutputStream os = new FileOutputStream ( “Test.txt? “append?;c) FileOutputStream fis = new FileOutputStream ( “Test.txt? “true?;d) FileOutputStream fis = new FileOutputStream (new File( “Test.txt?);e) OutputStream os = new OutputStream (new File( “Test.txt?, true);Ans AD253. public class test {public static void main(String args[]) {outer1: for(int k = 0; k < 3; k++) {outer2: for(int i = 0; i < 3; i++) {for(int j = 3; j >= 0; j--) {if(i >j)System.out.println(i + " " + j);break outer1;}}}}Ans 1 0254.class Super{int i=0;Super(){i=20;}void hello(){System.out.println("Afsal");

Page 42: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

}class Sub extends Super{int i =30;void hello(){System.out.println("Anson");}Sub(String s){ this.i=40;super.i=10;}public static void main(String args[]){Super b=new Sub("Anil");System.out.println(b.i);b.hello();}What will be printed? Select all correct ansA. Compilation ErrorB. Runtime Error10203040AnsonAfsalAns 10 Anson255. public static void main(String args[]){String s="Java";Stringbuffer s=new StringBuffer("Java");Change(s);Change(sb);System.out.println(s+sb);}public static void (String s){s="hello";}public static void Change(StringBuffer sb){sb=new StringBuffer("hello");}what will be printed?Ans JavaJava256.

public static void main(String args[]){System.out.println(args[1]);}What will be printed if you execute the program using java Program redgreen blueAns Green257.public static void main(String args[]){String s="Java";String s2=s;s2 +="Sun";s.concat("Java");System.out.println(s2 + s);}Write the answer?Ans javaSunjava258. What happens when the following program is compiled and run.Select the one correct answer.public class example {public static void main(String args[]) {int x= 2;int y=2change(x,y);System.out.println(x+" "+y);}public static change(int i,int j) {i = 4;j=4;}}The program does not compile.B. The program prints 2 2.The program prints 4 4.The program prints 4.The program prints 8.Ans B260. Which will stops execution of the a thread? Select oneexecute wait()changing priority valuecall terminate method from another threadAns A261. Which of the following is the is

Page 43: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

a subclass of Throwable?ThreadObjectExceptionThrowAns Thread262. Which of the following Listener is to handle "MouseMotionEvent"MouseMotionListenerMouseListenerMotionListenerActionListenerAns A263. class Super{ int i=0;Super(String s){i=10;}}class Sub extends Super{Sub(String s){ i=20; }public static void main(String args[]){Sub b=new Sub("hello");System.out.println(i);}What will be the value of i.?A. Compilation ErrorB. Runtime ErrorC. 0D. 10E. 20Ans A264.which of the following is the correct way(s) to openRandomAccessFile for append to a file using seek() methodFile f=new File(C:\\hello.txt");new RandomAccessFile(f,"rw");new RandomAccessFile(f,"r");new RandomAccessFile(f,"w");new RandomAccessFile(f,"a");Ans A265. Which of the following will give equal results?A. 6/2 B. 6>>2 C. 6*4 D.6>>>2

Ans BD266.. Identify two classes where objects are placed and retrieved bykey valueHashTableHashSetHashMapMapAns AC267. Which of the following is the most restrictive modifier for classvariable to be accessible for all the classes in the same package aswell as in subclasses?publicprotecteddefaultprivateAns B268.1. String s="hello";2. String s=null;3. System.gc();Is Garbage Collector will execute at line 3?Garbage collector will surely executeGarbage collector will not executeGarbage collector may executeAns C269. What will be the result of the following codeclass s1 extends Thread{public void run(){ for(int i=0;i<3;i++){System.out.println("A");System.out.println("B");}}}class s2 extends Thread{public void run(){ for(int i=0;i<3;i++){System.out.println("C");System.out.println("D");}}public static void main(String args[]){

Page 44: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

s1 t1=new s1();s2 t2=new s2();t1.start();t2.start();}}A) Compile time Error There is no start methodB) Will print in this order AB CD AB……C) Will print but not be able to predict the OrderD) Will print in this order ABCD……ABCD……Ans C271.You have the following code. Which numbers will cause "Test3" to beprinted?switch(x){case 1: System.out.println("Test1");case 2: System.out.println("Test2");case 4: System.out.println("Test4");case 3: System.out.println("Test3");break;}}A. 0B. 1C. 2D. 3E. 4Ans BCDE272.class a{public static void main(String ar[]){ int i=10;while: for( i=1;i<10;i++)if(i==5)continue while;System.out.println(i);}}Write the output?Ans Compilation Error273.class a{static String s;int i;public static void main(String ar[])

{ int i;String s="10";System.out.println("string is"+s);}What will be the out put?Ans string is 10274. Which of the following method is to handle MouseMotionEventprocessMouseMotionEvent()processMouseEvent()processMotionEvent()processEvent()Ans A275. A --------is a collection which can contain duplicate elementsand has an explicit order to its elementsSetMapCollectionListAns List276.class a{static String s;int i;public static void main(String ar[]){System.out.println("string is"+s);}What will be the out put?277.public static void main(String ar[]){int j=10;method(j);amethod(j);System.out.println(j);}public static method(int j){j++;}public static amethod(int j){j++;}}What will be the result?278. What is the range of byte in

Page 45: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

values?-128 to +127279. class s implements Runnable{int x,y;public void run(){for(;;)synchronized(this){x=12;y=12;}System.out.println(x+" "+y);}public static void main(String args[]){s run=new s();Thread t1=new Thread(run);Thread t2=new Thread(run);t1.start();t2.start();}}What will be the result?A. DeadLockB. Execute without any problems and print 12 12C. Compilation ErrorAns B //only one thread will be printing other thread will wait280. Which of the following is used to find maxmax()Math.max();None of the aboveAns C

310-025- 1 -

310-025Sun Java Certified ProgrammerVersion 1310-025- 3 -Question No: 1Given:

1. public class test (2. public static void main (String args[]) {3. int i = 0xFFFFFFF1;4. int j = ~i;5.6. }7. )What is the decimal value of j at line 5?A. 0B. 1C. 14D. –15E. An error at line 3 causes compilation to fail.F. An error at line 4 causes compilation to fail.Answer: CQuestion No: 2Given: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))Answer: D, E310-025- 4 -Question No: 3Exhibit :1. public class test (2. private static int j = 0;3.4. private static boolean methodB(int k) (5. j += k;6. return true;6. )7.

Page 46: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

8. public static void methodA(int i) {9. boolean b:10. b = i < 10 | methodB (4);11. b = i < 10 || methodB (8);12. )13.14. public static void main (String args[] } (15. methodA (0);16. system.out.printIn(j);17. )18. )What is the result?A. The program prints “0”B. The program prints “4”C. The program prints “8”D. The program prints “12”E. The code does not complete.Answer: BQuestion No: 4Given1. Public class test (2. Public static void main (String args[]) (3. System.out.printIn (6 ^ 3);4. )5. )What is the output?310-025- 5 -Answer: 5Question No: 5Given:1. public class Foo {2. public static void main (String [] args) {3. StringBuffer a = new StringBuffer (“A”);4. StringBuffer b = new StringBuffer (“B”);5. operate (a,b);6. system.out.printIn{a + “,” +b};

7. )8. static void operate (StringBuffer x, StringBuffer y) {9. x.append {y};10. y = x;11. )12. }What is the result?A. The code compiles and prints “A,B”.B. The code compiles and prints “A,A”.C. The code compiles and prints “B,B”.D. The code compiles and prints “AB,B”.E. The code compiles and prints “AB,AB”.F. The code does not compile because “+” cannot be overloaded for StringBuffer.Answer: DQuestion No: 6Exhibit:1. Public class test (2. Public static void stringReplace (String text) (3. Text = text.replace (‘j’ , ‘i’);4. )5.6. public static void bufferReplace (StringBuffer text) (7. text = text.append (“C”)8. )9.10. public static void main (String args[]} (310-025- 6 -11. String textString = new String (“java”);12. StringBuffer text BufferString = new StringBuffer (“java”);13.14. stringReplace (textString);15. BufferReplace

Page 47: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

(textBuffer);16.17. System.out.printIn (textString + textBuffer);18. }19. )What is the output?Answer: JAVAJAVAQuestion No: 7Exhibit:1. public class test {2. public static void add3 (Integer i) }3. int val = i.intValue ( );4. val += 3;5. i = new Integer (val);6. }7.8. public static void main (String args [ ] ) {9. Integer i = new Integer (0);10. add3 (i);11. system.out.printIn (i.intValue ( ) );12. }13. )What is the result?A. Compilation will fail.B. The program prints “0”.C. The program prints “3”.D. Compilation will succeed but an exception will be thrown at line 3.Answer: B310-025- 7 -Question No: 8Given:1. public class ConstOver {2. public ConstOver (int x, int y, int z) {3. }4. }Which two overload the ConstOver constructor? (Choose Two)A. ConstOver ( ) { }B. Protected int ConstOver ( ) { }

C. Private ConstOver (int z, int y, byte x) { }D. Public Object ConstOver (int x, int y, int z) { }E. Public void ConstOver (byte x, byte y, byte z) { }Answer: A, CQuestion No: 9Given:1. public class MethodOver {2. public void setVar (int a, int b, float c) {3. }4. }Which two overload the setVar method? (Choose Two)A. Private void setVar (int a, float c, int b) { }B. Protected void setVar (int a, int b, float c) { }C. Public int setVar (int a, float c, int b) (return a;)D. Public int setVar (int a, int b, float c) (return a;)E. Protected float setVar (int a, int b, float c) (return c;)Answer: A, CQuestion No: 10Given:1. class BaseClass {2. Private float x = 1.0f ;310-025- 8 -3. protected float getVar ( ) ( return x;)4. }5. class Subclass extends BaseClass (6. private float x = 2.0f;7. //insert code here8. )Which two are valid examples of method overriding? (Choose Two)A. Float getVar ( ) { return x;}B. Public float getVar ( ) { return x;}C. Float double getVar ( ) { return x;}D. Public float getVar ( ) { return x;}

Page 48: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

E. Public float getVar (float f ) { return f;}Answer: B, DQuestion No: 11Which two demonstrate an “is a” relationship? (Choose Two)A. public interface Person { }public class Employee extends Person { }B. public interface Shape { }public class Employee extends Shape { }C. public interface Color { }public class Employee extends Color { }D. public class Species { }public class Animal (private Species species;)E. interface Component { }Class Container implements Component (Private Component[ ] children;)Answer: D, EQuestion No: 12Which statement is true?A. An anonymous inner class may be declared as final.B. An anonymous inner class can be declared as private.C. An anonymous inner class can implement multiple interfaces.310-025- 9 -D. An anonymous inner class can access final variables in any enclosing scope.E. Construction of an instance of a static inner class requires an instance of the enclosing outer class.Answer: DQuestion No 13Given:1. package foo;2.

3. public class Outer (4. public static class Inner (5. )6. )Which statement is true?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()”Answer: AQuestion No 14Exhibit:1. public class enclosingone (2. public class insideone{}3. )4. public class inertest(5. public static void main (string[]args)(6. enclosingone eo= new enclosingone ();7. //insert code here8. )9. )Which statement at line 7 constructs an instance of the inner class?310-025- 10 -A. InsideOnew ei= eo.new InsideOn();B. Eo.InsideOne ei = eo.new InsideOne();C. InsideOne ei = EnclosingOne.new InsideOne();D. EnclosingOne.InsideOne ei = eo.new InsideOne();Answer: DQuestion No 15Exhibit:1. interface foo {

Page 49: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

2. int k = 0;3. ]4.5. public class test implements Foo (6. public static void main(String args[]) (7. int i;8. Test test = new test ();9. i= test.k;10.i= Test.k;11.i= Foo.k;12.)13.)14.What is the result?A. Compilation succeeds.B. An error at line 2 causes compilation to fail.C. An error at line 9 causes compilation to fail.D. An error at line 10 causes compilation to fail.E. An error at line 11 causes compilation to fail.Answer: AQuestion No 16Given:310-025- 11 -1. //point X2. public class foo (3. public static void main (String[]args) throws Exception {4. printWriter out = new PrintWriter (new5. java.io.outputStreamWriter (System.out), true;6. out.printIn(“Hello”);7. }8. )Which statement at PointX on line 1 allows this code to compile and run?A. Import java.io.PrintWriter;B. Include java.io.PrintWriter;

C. Import java.io.OutputStreamWriter;D. Include java.io.OutputStreamWriter;E. No statement is needed.Answer: AQuestion No 17Which two statements are reserved words in Java? (Choose Two)A. RunB. ImportC. DefaultD. ImplementAnswer: B, CQuestion No 18Which three are valid declarations of a float? (Choose Three)A. Float foo = -1;B. Float foo = 1.0;C. Float foo = 42e1;D. Float foo = 2.02f;E. Float foo = 3.03d;F. Float foo = 0x0123;Answer: A, D, F310-025- 12 -Question No 19Given:8. int index = 1;9. boolean[] test = new Boolean[3];10. boolean foo= test [index];What is the result?A. Foo has the value of 0.B. Foo has the value of null.C. Foo has the value of true.D. Foo has the value of false.E. An exception is thrown.F. The code will not compile.Answer: DQuestion No 20Given:1. public class test(2. public static void main(string[]args){3. string foo = args [1];4. string foo = args [2];5. string foo = args [3];

Page 50: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

6. }7. }And command line invocation:Java Test red green blueWhat is the result?A. Baz has the value of “”B. Baz has the value of nullC. Baz has the value of “red”D. Baz has the value of “blue”E. Bax has the value of “green”F. The code does not compile.G. The program throws an exception.310-025- 13 -Answer: GQuestion No 21Given:8. int index = 1;9. int [] foo = new int [3];10.int bar = foo [index];11.int baz = bar + index;What is the result?A. Baz has the value of 0B. Baz has the value of 1C. Baz has the value of 2D. An exception is thrown.E. The code will not compile.Answer: BQuestion No 22Given:1. public class foo {2. public static void main (String[]args) {3. String s;4. system.out.printIn (“s=” + s);5. }6. }What is the result?A. The code compiles and “s=” is printed.B. The code compiles and “s=null” is printed.C. The code does not compile because string s is not initialized.D. The code does not compile because string s cannot be referenced.E. The code compiles, but a

NullPointerException is thrown when toString is called.Answer: C310-025- 14 -Question No 23Which will declare a method that forces a subclass to implement it?A. Public double methoda();B. Static void methoda (double d1) {}C. Public native double methoda();D. Abstract public void methoda();E. Protected void methoda (double d1){}Answer: DQuestion No 24You want subclasses in any package to have access to members of a superclass. Which is the mostrestrictive access modifier that will accomplish this objective?A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is qualifiedAnswer: CQuestion No 25Given:1. abstract class abstrctIt {2. abstract float getFloat ();3. )4. public class AbstractTest extends AbstractIt {5. private float f1= 1.0f;6. private float getFloat () {return f1;}7. }What is the result?A. Compilation is successful.B. An error on line 6 causes a runtime failure.310-025- 15 -C. An error at line 6 causes compilation to fail.

Page 51: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

D. An error at line 2 causes compilation to fail.Answer: C310-025- 16 -Question No 26Exhibit:1. public class test(2. public int aMethod()[3. static int i=0;4. i++;5. return I;6. )7. public static void main (String args[]){8. test test = new test();9. test.aMethod();10.int j = test.aMethod();11.System.out.printIn(j);12.]13.}What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “0”C. Compilation will succeed and the program will print “1”D. Compilation will succeed and the program will print “2”Answer: DQuestion No 27Given:1. class super {2. public float getNum() {return 3.0f;}3. )4.5. public class Sub extends Super {6.7. )Which method, placed at line 6, will cause a compiler error?A. Public float getNum() {return 4.0f; }B. Public void getNum () { }C. Public void getNum (double d) { }310-025

- 17 -D. Public double getNum (float d) {retrun 4.0f; }Answer: BQuestion No 28Which declaration prevents creating a subclass of an outer class?A. Static class FooBar{}B. Private class FooBar{}C. Abstract public class FooBar{}D. Final public class FooBar{}E. Final abstract class FooBar{}Answer: DQuestion No 29Given:1. byte [] arry1, array2[];2. byte array3 [][];3. byte[][] array4;If each array has been initialized, which statement will cause a compiler error?A. Array2 = array1;B. Array2 = array3;C. Array2 = array4;D. Both A and BE. Both A and CF. Both B and CAnswer: FQuestion No 30Exhibit:310-025- 18 -1. class super (2. public int I = 0;3.4. public super (string text) (5. I = 16. )7. )8.9. public class sub extends super (10. public sub (string text) (11. i= 212. )13.

Page 52: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

14. public static void main (straing args[]) (15. sub sub = new sub (“Hello”);16. system.out. PrintIn(sub.i);17. )18. )What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “0”C. Compilation will succeed and the program will print “1”D. Compilation will succeed and the program will print “2”Answer: AQuestion No 31Given:1. public class returnIt (2. returnType methodA(byte x, double y) (3. return (short) x/y * 2;4. )5. )What is the valid returnType for methodA in line 2?A. IntB. ByteC. LongD. ShortE. Float310-025- 19 -F. DoubleAnswer: FQuestion No 32Given the ActionEvent, which method allows you to identify the affected component?A. GetClass.B. GetTarget.C. GetSource.D. GetComponent.E. GetTargetComponent.Answer: CQuestion No 33

Which is a method of the MouseMotionListener interface?A. Public void mouseMoved(MouseEvent)B. Public boolean mouseMoved(MouseEvent)C. Public void mouseMoved(MouseMotionEvent)D. Public boolean MouseMoved(MouseMotionEvent)E. Public boolean mouseMoved(MouseMotionEvent)Answer: A310-025- 20 -Question No 34Exhibit:1. import java.awt*;2.3. public class X extends Frame (4. public static void main(string []args) (5. X x = new X ();6. X.pack();7. x.setVisible(true);8. )9.10. public X () (11. setlayout (new GridLayout (2,2));12.13. Panel p1 = new panel();14. Add(p1);15. Button b1= new Button (“One”);16. P1.add(b1);17.18. Panel p2 = new panel();19. Add(p2);20. Button b2= new Button (“Two”);21. P2.add(b2);22.23. Button b3= new Button (“Three”);24. add(b3);

Page 53: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

25.26. Button b4= new Button (“Four”);27. add(b4);28. )29. )Which two statements are true? (Choose Two)A. All the buttons change height if the frame height is resized.B. All the buttons change width if the Frame width is resized.C. The size of the button labeled “One” is constant even if the Frame is resized.D. Both width and height of the button labeled “Three” might change if the Frame is resized.Answer: C, D310-025- 21 -Question No 35You are assigned the task of building a panel containing a TextArea at the top, a label directly below it,and a button directly below the label. If the three components are added directly to the panel. Whichlayout manager can the panel use to ensure that the TextArea absorbs all of the free vertical space whenthe panel is resized?A. GridLayout.B. CardLayout.C. FlowLayout.D. BorderLayout.E. GridBagLayout.Answer: EQuestion No 36Which gets the name of the parent directory file “file.txt”?A. String name= File.getParentName(“file.txt”);B. String name= (new File(“file.txt”)).getParent();C. String name = (new File(“file.txt”)).getParentName();D. String name= (new

File(“file.txt”)).getParentFile();E. Directory dir=(new File (“file.txt”)).getParentDir();String name= dir.getName();Answer: BQuestion No 37Which can be used to encode charS for output?A. Java.io.OutputStream.B. Java.io.OutputStreamWriter.C. Java.io.EncodeOutputStream.D. Java.io.EncodeWriter.E. Java.io.BufferedOutputStream.Answer: B310-025- 22 -Question No 38The file “file.txt” exists on the file system and contsins ASCII text.Given:38. try {39. File f = new File(“file.txt”);40. OutputStream out = new FileOutputStream(f, true);41. }42. catch (IOException) {}What is the result?A. The code does not compile.B. The code runs and no change is made to the file.C. The code runs and sets the length of the file to 0.D. An exception is thrown because the file is not closed.E. The code runs and deletes the file from the file system.Answer: AQuestion No 39Which constructs a DataOutputStream?A. New dataOutputStream(“out.txt”);B. New dataOutputStream(new file(“out.txt”));C. New dataOutputStream(new writer(“out.txt”));

Page 54: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

D. New dataOutputStream(new FileWriter(“out.txt”));E. New dataOutputStream(new OutputStream(“out.txt”));F. New dataOutputStream(new FileOutputStream(“out.txt”));Answer: FQuestion No 40What writes the text “<end>” to the end of the file “file.txt”?A. OutputStream out= new FileOutputStream (“file.txt”);Out.writeBytes (“<end>/n”);B. OutputStream os= new FileOutputStream (“file.txt”, true);DataOutputStream out = new DataOutputStream(os);out.writeBytes (“<end>/n”);310-025- 23 -C. OutputStream os= new FileOutputStream (“file.txt”);DataOutputStream out = new DataOutputStream(os);out.writeBytes (“<end>/n”);D. OutputStream os= new OutputStream (“file.txt”, true);DataOutputStream out = new DataOutputStream(os);out.writeBytes (“<end>/n”);Answer: BQuestion No 41Given:1. public class X (2. public object m () {3. object o = new float (3.14F);4. object [] oa = new object [1];5. oa[0]= o;6. o = null;7. return oa[0];8. }9. }When is the float object created in line 3, eligible for garbage collection?

A. Just after line 5B. Just after line 6C. Just after line 7 (that is, as the method returns)D. Never in this method.Answer: D310-025- 24 -Question No 42Given:3. string foo = “ABCDE”;4. foo.substring(3);5. foo.concat(“XYZ”);6.Type the value of foo at line 6.Answer: ABCDEQuestion No 43Which method is an appropriate way to determine the cosine of 42 degrees?A. Double d = Math.cos(42);B. Double d = Math.cosine(42);C. Double d = Math.cos(Math.toRadians(42));D. Double d = Math.cos(Math.toDegrees(42));E. Double d = Math.cosine(Math.toRadians(42));Answer: CQuestion No 44You need to store elements in a collection that guarantees that no duplicates are stored and all elementscan be accessed in natural order. Which interface provides that capability?A. Java.util.Map.B. Java.util.Set.C. Java.util.List.D. Java.util.StoredSet.E. Java.util.StoredMap.F. Java.util.Collection.Answer: DQuestion No 45Which statement is true for the class java.util.HashSet?310-025- 25 -A. The elements in the collection are

Page 55: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

ordered.B. The collection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.E. The elements in the collections are guaranteed to be synchronized.Answer: CQuestion No 46Given:1. public class IfTest (2. public static void main(string[]args) {3. int x = 3;4. int y = 1;5. if (x = y)6. system.out.printIn(“Not equal”);7. else8. system.out.printIn(“Equal”);9. }10. )What is the result?A. The output is “Equal”B. The output in “Not Equal”C. An error at line 5 causes compilation to fall.D. The program executes but does not print a message.Answer: CQuestion No 47Exhibit:1. public class test (2. public static void main(string args[]) {3. int 1= 0;4. while (i) {5. if (i==4) {6. break;310-025- 26 -7. )8. ++i;9. )

10.11. )12. )What is the value of i at line 10?A. 0B. 3C. 4D. 5E. The code will not compile.Answer: EQuestion No 48Given:3. int i= 1, j= 10 ;4. do (5. if (i++> --j) continue;6. ) while (i<5);After execution, what are the values for I and j?A. i = 6 and j= 5B. i = 5 and j= 5C. i = 6 and j= 4D. i = 5 and j= 6E. i = 6 and j= 6Answer: DQuestion No 49Given:1. switch (i) {2. default:310-025- 27 -3. System.out.printIn(“Hello”);4. )What are the two acceptable types for the variable i? (Choose Two)A. CharB. ByteC. FloatD. DoubleE. ObjectAnswer: A, BQuestion No 50Given:1. public class foo {2. public static void main (string[]args)3. try {return;}

Page 56: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

4. finally {system.out.printIn(“Finally”);}5. }6. )What is the result?A. The program runs and prints nothing.B. The program runs and prints “Finally”C. The code compiles, but an exception is thrown at runtime.D. The code will not compile because the catch block is missing.Answer: B310-025- 28 -Question No 51Exhibit:1. import java.io.IOException;2. public class ExceptionTest(3. public static void main (String[]args)4. try (5. methodA();6. ) catch (IOException e) (7. system.out.printIn(“Caught IOException”);8. ) catch (Exception e) (9. system.out.printIn(“Caught Exception”);10. )11. )12. public void methodA () {13. throw new IOException ();14. )15. )What is the result?A. The code will not compile.B. The output is caught exception.C. The output is caught IOException.D. The program executes normally without printing a message.Answer: A

Question No 52Exhibit:1. public class test {2. public static string output = “”3.4. public static void foo(int i) {5. try {6. if(i= =1) {7. throw new Exception ();8. }9. output += “1”;10. )11. catch(Exception e) {310-025- 29 -12. output += “2”;13. return;14. )15. finally (16. output += “3”;17. )18. output += “4”;19. )20.21. public static void main (string args[]) (22. foo(0);23. foo(1);24.25. )26. )What is the value of the variable output at line 24?Answer: 13423Question No 53Given:1. public class Foo implements Runnable (2. public void run (Thread t) {3. system.out.printIn(“Running.”);4. }5. public static void main

Page 57: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

(String[] args) {6. new thread (new Foo()).start();7. )8. )What is the result?A. An exception is thrown.B. The program exists without printing anything.C. An error at line 1 causes compilation to fail.D. An error at line 2 causes the compilation to fail.E. “Running” is printed and the program exits.Answer: D310-025- 30 -Question No 54Which statement is true?A. If only one thread is blocked in the wait method of an object, and another thread executes themodify on that same object, then the first thread immediately resumes execution.B. If a thread is blocked in the wait method of an object, and another thread executes the notifymethod on the same object, it is still possible that the first thread might never resume execution.C. If a thread is blocked in the wait method of an object, and another thread executes the notifymethod on the same object, then the first thread definitely resumes execution as a direct and soleconsequence of the notify call.D. If two threads are blocked in the wait method of one object, and another thread executes the notifymethod on the same object, then the first thread that executed the wait call first definitely resumesexecution as a direct and sole consequence of the notify call.

Answer: BQuestion No 55Which two CANNOT directly cause a thread to stop executing? (Choose Two)A. Calling the yield method.B. Calling the wait method on an object.C. Calling the notify method on an object.D. Calling the notifyAll method on an object.E. Calling the start method on another Thread object.Answer: C, DQuestion No 56Which two can be used to create a new Thread? (Choose Two)A. Extend java.lang.Thread and override the run method.B. Extend java.lang.Runnable and override the start method.C. Implement java.lang.thread and implement the run method.D. Implement java.lang.Runnable and implement the run method.E. Implement java.lang.Thread and implement the start method.Answer: A, D310-025- 31 -Question No 57Given:1. public class SyncTest (2. private int x;3. private int y;4. private synchronized void setX (int i) (x=1;)5. private synchronized void setY (int i) (y=1;)6. public void setXY(int 1)(set X(i); setY(i);)7. public synchronized Boolean check() (return x !=y;)8. )Under which conditions will check () return true when called from a different class?A. Check() can never return true.

Page 58: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

B. Check() can return true when setXY is called by multiple threads.C. Check() can return true when multiple threads call setX and setY separately.D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.Answer: BQuestion No 58Exhibit:1. class A implements runable (2. int i;3. public void run () (4. try (5. thread.sleep(5000);6. i= 10;7. ) catch(InterruptedException e) {}8. )9. )10.11. public class Test {12. public static void main (string args[]) (13. try (14. A a = new A ();15. Thread t = new Thread (a);16. t.start();310-025- 32 -17.18. int j= a.i;19.20. ) catch (Exception e) {}21. )22. )Which statement al line 17 will ensure that j=10 at line 19?A. a.wait();B. t.wait();C. t.join();D. t.yield();E. t.notify();F. a.notify();

G. t.interrupt();Answer: CQuestion No 59Exhibit:1. public class X implements Runnable (2. private int x;3. private int y;4.5. public static void main(String [] args) (6. X that = new X();7. (new Thread(that)) . start( );8. (new Thread(that)) . start( );9. )10.11. public synchronized void run( ) (12. for (;;) (13. x++;14. y++;15. System.out.printIn(“x = “ + x + “, y = “ + y);16. )17. )18. )What is the result?310-025- 33 -A. An error at line 11 causes compilation to fail.B. Errors at lines 7 and 8 cause compilation to fail.C. The program prints pairs of values for x and y that might not always be the same on the same line(for example, “x=2, y=1”)D. The program prints pairs of values for x and y that are always the same on the same line (forexample, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by“x=1, y=1”)E. The program prints pairs of values for x

Page 59: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

and y that are always the same on the same line (forexample, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by“x=2s, y=2”)Answer: EQUESTION NO: 60Which two CANNOT directly cause a thread to stop executing? (Choose Two)A. Existing from a synchronized block.B. Calling the wait method on an object.C. Calling notify method on an object.D. Calling read method on an InputStream object.E. Calling the SetPriority method on a Thread object.Answer: A, CQUESTION NO: 61Exhibit1. public class SyncTest{2. public static void main(String[] args) {3. final StringBuffer s1= new StringBuffer();4. final StringBuffer s2= new StringBuffer();5. new Thread () {6. public void run() {7. synchronized(s1) {8. s2.append(“A”);9. synchronized(s2) {10. s2.append(“B”);11. System.out.print(s1);12. System.out.print(s2);13. }310-025- 34 -14. }15. }16. }.start();17. new Thread() {18. public void run() {19. synchronized(s2) {20. s2.append(“C”);21. synchronized(s1) {22. s1.append(“D”);

23. System.out.print(s2);24. System.out.print(s1);25. }26. }27. }28. }.start();29. }30. }Which two statements are true? (Choose Two)A. The program prints “ABBCAD”B. The program prints “CDDACB”C. The program prints “ADCBADBC”D. The output is a non-deterministic point because of a possible deadlock condition.E. The output is dependent on the threading model of the system the program is running on.Answer: D, BQUESTION NO: 62Which method in the Thread class is used to create and launch a new thread of execution?A. Run();B. Start();B. Execute();C. Run(Runnable r);D. Start(Runnable r);E. Execute(Thread t);Answer: B310-025- 35 -QUESTION NO: 63Given:5. String foo = “base”;6. foo.substring(0,3);7. foo.concat(“ket”)8.Type the value of foo at line 8.Answer: BASEQUESTION NO: 64Which code determines the int value foo closest to, but not greater than, a double value bar?A. Int foo = (int) Math.max(bar);B. Int foo = (int) Math.min(bar);C. Int foo = (int) Math.abs(bar);

Page 60: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

D. Int foo = (int) Math.ceil(bar);E. Int foo = (int) Math.floor(bar);F. Int foo = (int) Math.round(bar);Answer: EQUESTION NO: 65Which statement is true?A. A flow layout can be used to position a component that should resize horizontally when thecontainer is resized.B. A grid layout can be used to position a component tat should maintain a constant size even whenthe container is resized.C. A border layout can be used to position component that should maintain a constant size even whenthe container is resized.D. The grid bag layout can be used to give a grid-like layout which differs from the normal grid inthat individual rows and columns can have unique sizes.E. If two components are placed in the same column of a grid bag layout, and one component resizeshorizontally, then the other component must resize horizontally.Answer: D310-025- 36 -QUESTION NO: 66Given an ActionEvent, which method allows you to identify the affected Component?A. Public class getClass()B. Public Object getSource()C. Public Component getSource()D. Public Component getTarget()E. Public Component getComponent()F. Public Component getTargetComponent()Answer: BQUESTION NO: 67Exhibit:1. import java.awt.*;

2.3. public class Test extends Frame {4. public Test() {5. add(new Label(“Hello”) );6. add(new TextField(“Hello”) );7. add(new Button(“Hello”) );8. pack();9. show();10. }11.12. public static void main(String args[]) {13. new Test ();14. }15. )What is the result?A. The code will not compile.B. A Window will appear containing only a Button.C. An IllegalArgumentException is thrown at line 6.D. A Window button will appear but will not contain the Label, TextField, or Button.E. A Window will appear containing a Label at the top, a TextField below the Label, and a Buttonbelow the TextField.F. A Window will appear containing a Label on the left, a TextField to the right of the Label, and abutton to the right of the TextField.310-025- 37 -Answer: BQUESTION NO: 68Exhibit:1. class A {2. public int getNumber(int a) {3. return a + 1;4. }5. }6.

Page 61: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

7. class B extends A {8. public int getNumber (int a) {9. return a + 210. }11.12. public static void main (String args[]) {13. A a = new B();14. System.out.printIn(a.getNumber(0));15. }16. }What is the result?A. Compilation succeeds and 1 is printed.B. Compilation succeeds and 2 is printed.C. An error at line 8 causes compilation to fail.D. An error at line 13 causes compilation to fail.E. An error at line 14 causes compilation to fail.Answer: BQUESTION NO: 69Given:1. class BaseClass{2. private float x= 1.0f;3. protected void setVar (float f) {x = f;}4. }310-025- 38 -5. class SubClass exyends BaseClass {6. private float x = 2.0f;7. //insert code here8. }Which two are valid examples of method overriding? (Choose Two)A. Void setVar(float f) {x = f;}B. Public void setVar(int f) {x = f;}C. Public void setVar(float f) {x = f;}D. Public double setVar(float f) {x = f;}E. Public final void setVar(float f) {x = f;}F. Protected float setVar() {x=3.0f; return 3.0f; }

Answer: C, EQUESTION NO: 70Which statement about static inner classes is true?A. An anonymous class can be declared as static.B. A static inner class cannot be a static member of the outer class.C. A static inner class does not require an instance of the enclosing class.D. Instance members of a static inner class can be referenced using the class name of the static innerclass.Answer: CQUESTION NO: 71Exhibit:1. class A {2. public byte getNumber () {3. return 1;4. }5. }6.7. class B extends A {8. public short getNumber() {9. return 2;10. }310-025- 39 -11.12. public static void main (String args[]) {13. B b = new B ();14. System.out.printIn(b.getNumber())15. }16. }What is the result?A. Compilation succeeds and 1 is printed.B. Compilation succeeds and 2 is printed.C. An error at line 8 causes compilation to fail.D. An error at line 14 causes compilation to fail.

Page 62: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

E. Compilation succeeds but an exception is thrown at line 14.Answer: CQUESTION NO: 72Given:AnInterface is an interface.AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor thattakes one int argument.Which two construct an anonymous inner class? (Choose Two)F. AnAdapter1 aa=new AnAdapter1(){}G. AnAdapter0 aa=new AnAdapter0(){}H. AnAdapter0 aa=new AnAdapter0(5){}I. AnAdapter1 aa=new AnAdapter1(5){}J. AnInterface a1=new AnInterface(5){}Answer: B, DQUESTION NO: 73Which two statements are true? (Choose Two)A. An inner class may be declared as static.310-025- 40 -B. An anonymous inner class can be declared as public.C. An anonymous inner class can be declared as private.D. An anonymous inner class can extend an abstract class.E. An anonymous inner class can be declared as protected.Answer: A, DQUESTION NO: 74Exhibit:1. public class Mycircle {2. public double radius;3. public double diameter;4.5. public void setRadius(double radius)6. this.radius = radius;7. this.diameter= radius * 2;

8. }9.10. public double getRadius() {11. return radius;12. }13. }Which statement is true?A. The Mycircle class is fully encapsulated.B. The diameter of a given MyCircle is guaranteed to be twice its radius.C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation.D. The radius of a MyCircle object can be set without affecting its diameter.Answer: BQUESTION NO: 75You want to limit access to a method of a public class to members of the same class. Which accessmodifier accomplishes this objective?A. PublicB. Private310-025- 41 -C. ProtectedD. TransientE. No access modifier is requiredAnswer: BQUESTION NO: 76Exhibit:ClassOne.java1. package com.abc.pkg1;2. public class ClassOne {3. private char var = ‘a’;4. char getVar() {return var;}5. }ClassTest.java1. package com.abc.pkg2;2. import com.abc.pkg1.ClassOne;3. public class ClassTest extends ClassOne {4. public static void

Page 63: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

main(String[]args) {5. char a = new ClassOne().getVar();6. char b = new ClassTest().getVar();7. }8. }What is the result?A. Compilation will fail.B. Compilation succeeds and no exceptions are thrown.C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.Answer: BQUESTION NO: 77Given:1. public class ArrayTest {310-025Leading the way in IT testing and certification tools, www.testking.com- 42 -2. public static void main (String[]args) {3. float f1[], f2[];4. f1 = new float [10];5. f2 = f1;6. System.out.printIn (“f2[0]=” + f2[0]);7. }8. }What is the result?A. It prints f2[0] = 0.0B. It prints f2[0] = NaNC. An error at line 5 causes compile to fail.D. An error at line 6 causes compile to fail.E. An error at line 6 causes an exception at runtime.Answer: AQUESTION NO: 78Which two statements are true regarding the creation of a default constructor? (Choose Two)A. The default constructor initializes

method variables.B. The compiler always creates a default constructor for every class.C. The default constructor invokes the no-parameter constructor of the superclass.D. The default constructor initializes the instance variables declared in the class.E. When a class has only constructors with parameters, the compiler does not create a defaultconstructor.Answer: D, EQUESTION NO: 79Exhibit:1. class super {2. public int getLength() {return 4;}3. }4.5. public class Sub extends Super {6. public long getLength() {return 5;}7.310-025- 43 -8. public static void main (String[]args) {9. super sooper = new Super ();10. Sub sub = new Sub();11. System.out.printIn(12. sooper.getLength()+ “,” + sub.getLength() };13. }14. }What is the output?A. 4, 4B. 4, 5C. 5, 4D. 5, 5E. The code will not compile.Answer: EQUESTION NO: 80Given:1. public abstract class Test {

Page 64: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

2. public abstract void methodA();3.4. public abstract void methodB()5. {6. System.out.printIn(“Hello”);7. }8. }Which three changes (made independently) allow the code to compile? (Choose Three)A. Add a method body to methodA.B. Replace lines 5-7 with a semicolon (“.”)C. Remove the abstract qualifier from the declaration of Test.D. Remove the abstract qualifier from the declaration of methodB.E. Remove the abstract qualifier from the declaration of methodA.F. Remove methodB in its entirely and change class o interface in line 1.Answer: B, D, F310-025- 44 -QUESTION NO: 81Which determines if “prefs” is a directory and exists on the file system?A. Boolean exists=Directory.exists (“prefs”);B. Boolean exists=(new File(“prefs”)).isDir();C. Boolean exists=(new Directory(“prefs”)).exists();D. Boolean exists=(new File(“prefs”)).isDirectory();E. Boolean exists=true;Try{Directory d = new Directory(“prefs”);}catch (FileNotFoundException e) {exists = false;}Answer: DQUESTION NO: 82

Which two create an InputStream and open file the “file.txt” for reading? (Choose Two)A. InputStream in=new FileReader(“file.txt”);B. InputStream in=new FileInputStream(“file.txt”);C. InputStream in=new InputStreamFileReader (“file.txt”, “read”);D. FileInputStream in=new FileReader(new File(“file.txt”));E. FileInputStream in=new FileInputStream(new File(“file.txt”));Answer: B, EQUESTION NO 83Which two construct an OutputSream that appends to the file “file.txt”? (Choose Two)A. OutputStream out=new FileOutputStream(“file.txt”);B. OutputStream out=new FileOutputStream(“file.txt”, “append”);C. FileOutputStream out=new FileOutputStream(“file.txt”, true);D. FileOutputStream out=new FileOutputStream(new file(“file.txt”));E. OutputStream out=new FileOutputStream(new File(“file.txt”)true);Answer: C, E310-025- 45 -QUESTION NO: 84Which constructs a BufferedIputStream?A. New BufferedInputStream(“in.txt”);B. New BufferedInputStream(new File(“in.txt”));C. New BufferedInputStream(new Writer(“in.txt”));D. New BufferedInputStream(new Writer(“in.txt”));E. New BufferedInputStream(new InputStream(“in.txt”));F. New BufferedInputStream(new

Page 65: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

FileInputStream(“in.txt”));Answer: FQUESTION NO: 85Which is a valid identifier?A. falseB. defaultC. _objectD. a-classAnswer: CQUESTION NO: 86Exhibit:1. package foo;2.3. import java.util.Vector;4.5. private class MyVector extends Vector {6. int i = 1;7. public MyVector() {8. i = 2;9. }10. }11.12. public class MyNewVector extends MyVector {310-025- 46 -13. public MyNewVector () {14. i = 4;15. }16. public static void main (String args []) {17. MyVector v = new MyNewVector();18. }19. }The file MyNewVector.java is shown in the exhibit.What is the result?A. Compilation will succeed.B. Compilation will fail at line 5.C. Compilation will fail at line 6.D. Compilation will fail at line 14.E. Compilation will fail at line 17.Answer: BQUESTION NO: 87Given:

1. public class Test {2. public static void main (String[]args) {3. String foo = args[1];4. String bar = args[2];5. String baz = args[3];6. System.out.printIn(“baz = ” + baz);7. }8. }And the output:Baz = 2Which command line invocation will produce the output?A. Java Test 2222B. Java Test 1 2 3 4C. Java Test 4 2 4 2D. Java Test 4 3 2 1Answer: C310-025- 47 -QUESTION NO: 88Given:8. int index = 1;9. String [] test = new String[3];10. String foo = test[index];What is the result?E. Foo has the value “”B. Foo has the value nullC. An exception is thrownD. The code will not compileAnswer: BQUESTION NO: 89Given:1. public interface Foo{2. int k = 4;3. }Which three are equivalent to line 2? (Choose Three)A. Final int k = 4;B. Public int k = 4;C. Static int k = 4;D. Private int k = 4;E. Abstract int k = 4;F. Volatile int k = 4;

Page 66: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

G. Transient int k = 4;H. Protected int k = 4;Answer: A, B, CQUESTION NO: 90Given:310-025- 48 -1. public class foo {2. static String s;3. public static void main (String[]args) {4. system.out.printIn (“s=” + s);5. }6. }What is the result?A. The code compiles and “s=” is printed.B. The code compiles and “s=null” is printed.C. The code does not compile because string s is not initialized.D. The code does not compile because string s cannot be referenced.E. The code compiles, but a NullPointerException is thrown when toString is called.Answer: BQUESTION NO: 91Which two valid declarations of a char? (Choose Two)A. Char ch = “a”;B. Char ch = ‘\’ ‘;C. Char ch = ‘cafe’;D. Char ch = “cafe”;E. Char ch = ‘\ucafe’;F. Char ch = ‘\u10100’;G. Char ch = (char) true;Answer: B, EQUESTION NO: 92Given:1. String foo = “blue”;2. Boolean[]bar = new Boolean [1];3. if (bar[0]) {4. foo = “green”;5. }310-025- 49 -

What is the result?A. Foo has the value of “”B. Foo has the value of null.C. Foo has the value of “blue”D. Foo has the value of “green”E. An exception is thrown.F. The code will not compile.Answer: FQUESTION NO: 93Exhibit:1. public class X {2. public static void main (String[]args) {3. String s1 = new String (“true”);4. Boolean b1 = new Boolean (true);5. if (s2.equals(b1)) {6. System.out.printIn(“Equal”);7. }8. }9. }What is the result?A. The program runs and prints nothing.B. The program runs and prints “Equal”C. An error at line 5 causes compilation to fail.D. The program runs but aborts with an exception.Answer: AQUESTION NO: 94Given:1. public class Foo {2. public static void main (String []args) {3. int i = 1;310-025- 50 -4. int j = i++;5. if ((i>++j) && (i++ ==j)) {6. i +=j;7. }8. }9. }What is the final value of i?

Page 67: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

A. 1B. 2C. 3D. 4E. 5Answer: BQUESTION NO: 95Exhibit:1. public class X {2. public static void main (String[]args) {3. string s = new string (“Hello”);4. modify(s);5. System.out.printIn(s);6. }7.8. public static void modify (String s) {9. s += “world!”;10. }11. }What is the result?E. The program runs and prints “Hello”F. An error causes compilation to fail.G. The program runs and prints “Hello world!”H. The program runs but aborts with an exception.Answer: A310-025- 51 -QUESTION NO: 96Which two are equivalent? (Choose Two)A. 16>4B. 16/2C. 16*4D. 16>>2E. 16/2^2F. 16>>>2Answer: D, EQUESTION NO: 97Exhibit:1. public class X {2. public static void main (String[]args) {

3. int [] a = new int [1]4. modify(a);5. System.out.printIn(a[0]);6. }7.8. public static void modify (int[] a) {9. a[0] ++;10. }11. }What is the result?A. The program runs and prints “0”B. The program runs and prints “1”C. The program runs but aborts with an exception.D. An error “possible undefined variable” at line 4 causes compilation to fail.E. An error “possible undefined variable” at line 9 causes compilation to fail.Answer: B310-025- 52 -QUESTION NO: 98Given:13. public class Foo {14. public static void main (String [] args) {15. StringBuffer a = new StringBuffer (“A”);16. StringBuffer b = new StringBuffer (“B”);17. operate (a,b);18. system.out.printIn{a + “,” +b};19. )20. static void operate (StringBuffer x, StringBuffer y) {21. y.append {x};22. y = x;23. )24. }What is the result?A. The code compiles and prints “A,B”.B. The code compiles and prints “A, BA”.C. The code compiles and prints “AB, B”.D. The code compiles and prints “AB,

Page 68: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

AB”.E. The code compiles and prints “BA, BA”.F. The code does not compile because “+” cannot be overloaded for stringBuffer.Answer: BQUESTION NO: 99Given:1. public class X {2. public static void main (String[] args) {3. byte b = 127;4. byte c = 126;5. byte d = b + c;6. }7. }Which statement is true?A. Compilation succeeds and d takes the value 253.B. Line 5 contains an error that prevents compilation.C. Line 5 throws an exception indicating “Out of range”D. Line 3 and 4 contain error that prevent compilation.310-025- 53 -E. The compilation succeeds and d takes the value of 1.Answer: BQUESTION NO: 100Given:1. public class WhileFoo {2. public static void main (String []args) {3. int x= 1, y = 6;4. while (y--) {x--;}5. system.out.printIn(“x=” + x “y =” + y);6. }7. }What is the result?A. The output is x = 6 y = 0B. The output is x = 7 y = 0C. The output is x = 6 y = -1D. The output is x = 7 y = -1E. Compilation will fail.

Answer: EQUESTION NO: 101Which statement is true?A. The Error class is a untimeException.B. No exceptions are subclasses of Error.C. Any statement that may throw an Error must be enclosed in a try block.D. Any statement that may throw an Exception must be enclosed in a try block.E. Any statement that may thro a runtimeException must be enclosed in a try block.Answer: DQUESTION NO: 102Exhibit:310-025- 54 -1. int I=1, j=02.3. switch(i) {4. case 2:5. j+=6;6.7. case 4:8. j+=1;9.10. default:11. j +=2;12.13. case 0:14. j +=4;15. }16.What is the value of j at line 16?A. 0B. 1C. 2D. 4E. 6Answer: AEQUESTION NO: 103Given:1. switch (i) {2. default:3. System.out.printIn(“Hello”);4. )

Page 69: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

What is the acceptable type for the variable i?A. ByteB. LongC. FloatD. Double310-025- 55 -E. ObjectF. A and BG. C and DAnswer: AQUESTION NO: 104You need to store elements in a collection that guarantees that no duplicates are stored. Which twointerfaces provide that capability? (Choose Two)A. Java.util.MapB. Java.util.SetC. Java.util.ListD. Java.util.StoredSetE. Java.util.StoredMapF. Java.util.CollectionAnswer: B, DQUESTION NO: 105Which statement is true for the class java.util.ArrayList?A. The elements in the collection are ordered.B. The collection is guaranteed to be immutable.C. The elements in the collection are guaranteed to be unique.D. The elements in the collection are accessed using a unique key.E. The elements in the collections are guaranteed to be synchronized.Answer: AQUESTION NO: 106Exhibit:1. public class X implements Runnable(2. private int x;3. private int y;4.310-025

- 56 -5. public static void main(String[]args)6. X that = new X();7. (new Thread(that)).start();8. (new Thread(that)).start();9. )10.11. public void run() (12. for (;;) (13. x++;14. y++;15. System.out.printIn(“x=” + x + “, y = ” + y);16. )17. )18. )What is the result?A. Errors at lines 7 and 8 cause compilation to fail.B. The program prints pairs of values for x and y that might not always be the same on the same line(for example, “x=2, y=1”).C. The program prints pairs of values for x and y that are always the same on the same line (forexample, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by“x=1, y=1”).D. The program prints pairs of values for x and y that are always the same on the same line (forexample, “x=1, y=1”. In addition, each value appears only for once (for example, “x=1, y=1”followed by “x=2, y=2”).Answer: DQUESTION NO: 107Given:1. public class SyncTest {2. private int x;3. private int y;4. public synchronized void

Page 70: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

setX (int i) (x=1;)5. public synchronized void setY (int i) (y=1;)6. public synchronized void setXY(int 1)(set X(i); setY(i);)7. public synchronized Boolean check() (return x !=y;)8. )Under which conditions will check () return true when called from a different class?A. Check() can never return true.310-025- 57 -B. Check() can return true when setXY is called by multiple threads.C. Check() can return true when multiple threads call setX and setY separately.D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.Answer: AQUESTION NO: 108Which is a method of the MouseMotionListener interface?A. Public void mouseDragged(MouseEvent)B. Public boolean mouseDragged(MouseEvent)C. Public void mouseDragged(MouseMotionEvent)D. Public boolean MouseDragged(MouseMotionEvent)E. Public boolean mouseDragged(MouseMotionEvent)Answer: AQUESTION NO: 109Given:1. String foo = “base”;2. foo.substring(0,3);3. foo.concat(“ket”);4. foo += “ball”;5.Type the value of foo at line 8.Answer: BASEBALL

QUESTION NO 110Given:1. public class Test {2. public static void leftshift(int i, int j) {3. i<<=j;4. }5. public static void main(String args[]) {310-025- 58 -6. int i = 4, j = 2;7. leftshift(i, j);8. System.out.printIn(i);9. }10. }What is the result?A. 2B. 4C. 8D. 16E. The code will not compile.Answer: BQUESTION NO 111Given:1. public class Foo {2. private int val;3. public foo(int v) (val = v;) }4. public static void main (String [] args) {5. Foo a = new Foo (10);6. Foo b = new Foo (10);7. Foo c = a;8. int d = 10;9. double e = 10.0;10. }11. }Which three logical expression evaluate to true? (Choose Three)A. (a ==c)B. (d ==e)C. (b ==d)D. (a ==b)E. (b ==c)F. (d ==10.0)Answer: A, B, F

Page 71: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

310-025- 59 -QUESTION NO 112Exhibit:1. public class X {2. private static int a;3.5. public static void main (String[] args) {6. modify (a);7. }8.9. public static void modify (int a) {10. a++;11. }12. }What is the result?A. The program runs and prints “0”B. The program runs and prints “1”C. The program runs but aborts with an exception.D. En error “possible undefined variable” at line 5 causes compilation to fail.F. En error “possible undefined variable” at line 10 causes compilation to fail.Answer: AQUESTION NO 113Exhibit:1. public class Test {2. public static void replaceJ(string text) {3. text.replace (‘j’, ‘l’);4. }5.6. public static void main(String args[]) {7. string text = new String (“java”)8. replaceJ(text);9. system.out.printIn(text);10. }11. }310-025- 60 -What is the result?A. The program prints “lava”

B. The program prints “java”C. An error at line 7 causes compilation to fail.D. Compilation succeeds but the program throws an exception.Answer: BQUESTION NO 114Which two are equivalent? (Choose Two)A. 3/2B. 3<2C. 3*4D. 3<<2E. 3*2^2F. 3<<<2Answer: C, DQUESTION NO 115What is the numerical range of a char?A. 0 . . . 32767B. 0 . . . 65535C. –256 . . . 255D. –32768 . . . 32767E. Range is platform dependent.Answer: BQUESTION NO 116Given:1. public class Test {2. public static void main (String []args) {3. unsigned byte b = 0;310-025- 61 -4. b--;5.6. }7. }What is the value of b at line 5?A. -1B. 255C. 127D. Compilation will fail.E. Compilation will succeed but the program will throw an exception at line 4.Answer: DQUESTION NO 117Given:1. public class Foo {

Page 72: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

2. public void main (String [] args) {3. system.out.printIn(“Hello World.”);4. }5. }What is the result?A. An exception is thrown.B. The code does no compile.C. “Hello World.” Is printed to the terminal.D. The program exits without printing anything.Answer: AQUESTION NO 118Given:1. //point X2. public class foo (3. public static void main (String[]args) throws Exception {4. java.io.printWriter out = new java.io.PrintWriter (5. new java.io.outputStreamWriter (System.out), true;310-025- 62 -6. out.printIn(“Hello”);7. }8. }Which statement at PointX on line 1 allows this code to compile and run?A. Import java.io.*;B. Include java.io.*;C. Import java.io.PrintWriter;D. Include java.io.PrintWriter;E. No statement is needed.Answer: EQUESTION NO 119Which will declare a method that is available to all members of the same package and can be referencedwithout an instance of the class?A. Abstract public void methoda();B. Public abstract double methoda();C. Static void methoda(double d1){}

D. Public native double methoda() {}E. Protected void methoda(double d1) {}Answer: CQUESTION NO 120Which type of event indicates a key pressed on a java.awt.Component?A. KeyEventB. KeyDownEventC. KeyPressEventD. KeyTypedEventE. KeyPressedEventAnswer: AQUESTION NO 121310-025- 63 -Exhibit:1. import java.awt.*;2.3. public class X extends Frame {4. public static void main (String [] args) {5. X x = new X();6. x.pack();7. x.setVisible(true);8. }9.10. public X() {11. setLayout (new BordrLayout());12. Panel p = new Panel ();13. add(p, BorderLayout.NORTH);14. Button b = new Button (“North”);15. p.add(b):16. Button b = new Button (“South”);17. add(b1, BorderLayout.SOUTH):18. }19. }Which two statements are true? (Choose Two)A. The buttons labeled “North” and “South” will have the same width.B. The buttons labeled “North” and

Page 73: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

“South” will have the same height.C. The height of the button labeled “North” can very if the Frame is resized.D. The height of the button labeled “South” can very if the Frame is resized.E. The width of the button labeled “North” is constant even if the Frame is resized.F. The width of the button labeled “South” is constant even if the Frame is resized.Answer: B, EQUESTION NO 122How can you create a listener class that receives events when the mouse is moved?A. By extending MouseListener.B. By implementing MouseListener.C. By extending MouseMotionListener.D. By implementing MouseMotionListener.E. Either by extending MouseMotionListener or extending MouseListener.F. Either by implementing MouseMotion Listener or implementing MouseListener.310-025- 64 -Answer: DQUESTION NO 123Which statement is true?A. A grid bag layout can position components such that they span multiple rows and/or columns.B. The “North” region of a border layout is the proper place to locate a menuBar component in aFrame.C. Components in a grid bag layout may either resize with their cell, or remain centered in that cell attheir preferred size.D. A border layout can be used to position a component that should maintain a constant size evenwhen the container is resized.Answer: A

QUESTION NO 124You want a class to have access to members of another class in the same package. Which is the mostrestrictive access modifier that will accomplish that will accomplish this objective?A. PublicB. PrivateC. ProtectedD. TransientE. No access modifier is required.Answer: E310-025- 65 -QUESTION NO 125Which two statements are true regarding the creation of a default constructor? (Choose Two)A. The default constructor initializes method variables.B. The default constructor invokes the no-parameter constructor of the superclass.C. The default constructor initializes the instance variables declared in the class.D. If a class lacks a no-parameter constructor,, but has other constructors, the compiler creates adefault constructor.E. The compiler creates a default constructor only when there are no other constructors for the class.Answer: C, EQUESTION NO 126Given:1. public class OuterClass {2. private double d1 1.0;3. //insert code here4. }You need to insert an inner class declaration at line2. Which two inner class declarations are valid?(Choose Two)A. static class InnerOne {public double methoda() {return d1;}}B. static class InnerOne {

Page 74: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

static double methoda() {return d1;}}C. private class InnerOne {public double methoda() {return d1;}}D. protected class InnerOne {static double methoda() {return d1;}}E. public abstract class InnerOne {public abstract double methoda();}Answer: C, E310-025- 66 -QUESTION NO 127Which two declarations prevent the overriding of a method? (Choose Two)A. Final void methoda() {}B. Void final methoda() {}C. Static void methoda() {}D. Static final void methoda() {}E. Final abstract void methoda() {}Answer: A, DQUESTION NO 128Given:1. public class Test {2. public static void main (String args[]) {3. class Foo {4. public int i = 3;5. }6. Object o = (Object) new Foo();7. Foo foo = (Foo)o;8. System.out.printIn(foo. i);9. }10. }What is the result?A. Compilation will fail.B. Compilation will succeed and the program will print “3”C. Compilation will succeed but the program will throw a ClassCastException at line 6.D. Compilation will succeed but the program will throw a ClassCastException

at line 7.Answer: BQUESTION NO 129Which two create an instance of an array? (Choose Two)A. int[] ia = new int [15];B. float fa = new float [20];C. char[] ca = “Some String”;D. Object oa = new float[20];310-025- 67 -E. Int ia [][] = (4, 5, 6) (1, 2, 3)Answer: A, DQUESTION NO 130Given:1. public class ExceptionTest {2. class TestException extends Exception {}3. public void runTest () throws TestException {}4. public void test () /* Point X*/ {5. runTest ();6. }7. }At point X on line 4, which code can be added to make the code compile?A. Throws Exception.B. Catch (Exception e).C. Throws RuntimeException.D. Catch (TestException e).E. No code is necessary.Answer: BQUESTION NO 131Exhibit:1. public class SwitchTest {2. public static void main (String []args) {3. System.out.PrintIn(“value =” +switchIt(4));4. }5. public static int switchIt(int x) {6. int j = 1;7. switch (x) {8. case 1: j++;

Page 75: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

9. case 2: j++;10. case 3: j++;11. case 4: j++;12. case 5: j++;13. default:j++;- 68 -14. }15. return j + x;16. }17. }What is the output from line 3?A. Value = 3B. Value = 4C. Value = 5D. Value = 6E. Value = 7F. Value = 8Answer: FQUESTION NO 132Which four types of objects can be thrown using the throw statement? (Choose Four)A. ErrorB. EventC. ObjectD. ExceptionE. ThrowableF. RuntimeExceptionAnswer: A, D, E, FQUESTION NO 133Given:1. public class ForBar {2. public static void main(String []args) {3. int i = 0, j = 5;4. tp: for (;;) {5. i ++;6. for(;;)7. if(i > --j) break tp;8. }9. system.out.printIn(“i = ” + i + “, j = “+ j);310-025- 69 -10. }11. }What is the result?A. The program runs and prints “i=1, j=0”

B. The program runs and prints “i=1, j=4”C. The program runs and prints “i=3, j=4”D. The program runs and prints “i=3, j=0”E. An error at line 4 causes compilation to fail.F. An error at line 7 causes compilation to fail.Answer: AQUESTION NO 134Which two can directly cause a thread to stop executing? (Choose Two)A. Exiting from a synchronized block.B. Calling the wait method on an object.C. Calling the notify method on an object.D. Calling the notifyAll method on an object.E. Calling the setPriority method on a thread object.Answer: B, EQUESTION NO 135Given:1. public class Foo implements Runnable (2. public void run (Thread t) {3. system.out.printIn(“Running.”);4. }5. public static void main (String[] args) {6. new thread (new Foo()).start();7. )8. )What is the result?A. An exception is thrown.B. The program exists without printing anything.310-025- 70 -C. An error at line 1 causes compilation to fail.D. An error at line 6 causes the compilation to fail.E. “Running” is printed and the program exits.

Page 76: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

Answer: CQUESTION NO 136Which constructs a DataOutputStream?A. New dataInputStream(“in.txt”);B. New dataInputStream(new file(“in.txt”));C. New dataInputStream(new writer(“in.txt”));D. New dataInputStream(new FileWriter(“in.txt”));E. New dataInputStream(new InputStream(“in.txt”));F. New dataInputStream(new FileInputStream(“in.txt”));Answer: FQUESTION NO 137Which can be used to decode charS for output?A. Java.io.InputStream.B. Java.io.EncodedReader.C. Java.io.InputStreamReader.D. Java.io.InputStreamWriter.E. Java.io.BufferedInputStream.Answer: CQUESTION NO 138Given:1. public class Test {2. public static void main (String [] args) {3. string foo = “blue”;4. string bar = foo;5. foo = “green”;6. System.out.printIn(bar);310-025- 71 -7. }8. }What is the result?A. An exception is thrown.B. The code will not compile.C. The program prints “null”D. The program prints “blue”E. The program prints “green”Answer: DQUESTION NO 139Which code determines the int value foo

closest to a double value bar?A. Int foo = (int) Math.max(bar);B. Int foo = (int) Math.min(bar);C. Int foo = (int) Math.abs(bar);D. Int foo = (int) Math.ceil(bar);E. Int foo = (int) Math.floor(bar);F. Int foo = (int) Math.round(bar);Answer: FQUESTION NO 140Which two demonstrate encapsulation of data? (Choose Two)A. Member data have no access modifiers.B. Member data can be modified directly.C. The access modifier for methods is protected.D. The access modifier to member data is private.E. Methods provide for access and modification of data.Answer: D, EQUESTION NO 141310-025- 72 -Exhibit:1. class A {2. public String toString () {3. return “4”;4. }5. }6. class B extends A {7. 8. public String toString () {8. return super.toString() + “3”;9. }10. }11. public class Test {12. public static void main(String[]args) {13. System.out.printIn(new B());14. }15. }What is the result?A. Compilation succeeds and 4 is printed.B. Compilation succeeds and 43 is

Page 77: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

printed.C. An error on line 9 causes compilation to fail.D. An error on line 14 causes compilation to fail.E. Compilation succeeds but an exception is thrown at line 9.Answer: BQUESTION NO 142Which two statements are true? (Choose Two)A. An anonymous inner class can be declared inside of a methodB. An anonymous inner class constructor can take arguments in some situation.C. An anonymous inner class that is a direct subclass that is a direct subclass of Object can implementmultiple interfaces.D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymousinner class that is an immediate subclass of Super that implements a single interface.E. Event if a class Super does not implement any interfaces, it is still possible to define an anonymousinner class that is an immediate subclass of Super that implements multiple interfaces.Answer: A, B- 73 -QUESTION NO 143Given:1. public class MethodOver {2. private int x, y;3. private float z;4. public void setVar(int a, int b, float c){5. x = a;6. y = b;7. z = c;8. }9. }Which two overload the setVar method? (Choose Two)

A. void setVar (int a, int b, float c){x = a;y = b;z = c;}B. public void setVar(int a, float c, int b) {setVar(a, b, c);}C. public void setVar(int a, float c, int b) {this(a, b, c);}D. public void setVar(int a, float b){x = a;z = b;}E. public void setVar(int ax, int by, float cz) {x = ax;y = by;z = cz;}Answer: B, DQUESTION NO 144Which statements about static inner classes are true? (Choose Two)A. A static inner class requires a static initializer.B. A static inner class requires an instance of the enclosing class.- 74 -C. A static inner class has no reference to an instance of the enclosing class.D. A static inner class has access to the non-static members of the outer class.E. Static members of a static inner class can be referenced using the class name of the static innerclass.Answer: C, EQUESTION NO 145Given:1. public class X {2. public object m () {3. object o = new float (3.14F);4. object [] oa = new object [1];

Page 78: read.pudn.comread.pudn.com/downloads92/doc/359648/SUN JAVA2 FINAL.doc  · Web view1. Which statement are characteristics of the >> and >>> operators. A. >> performs a shift. B. >>

5. oa[0]= o;6. o = null;7. oa[0] = null;9. return o;9. }10. }When is the float object created in line 3, eligible for garbage collection?A. Just after line 5.B. Just after line 6.C. Just after line 7.D. Just after line 8(that is, as the method returns).Answer: CQUESTION NO 146Which two interfaces provide the capability to store objects using a key-value pair? (Choose Two)A. Java.util.Map.B. Java.util.Set.C. Java.util.List.D. Java.util.StoredSet.E. Java.util.StoredMap.F. Java.util.Collection.310-025- 75 -Answer: A, EQUESTION NO 147Which interface does java.util.Hashable implement?A. Java.util.Map.B. Java.util.List.C. Java.util.Hashable.D. Java.util.Collection.Answer: A