![]() |
About | Contact | Site Map | Mirror |
Voodoo Exam | Question Bank | Databases | Tutorials |
Exam 3 Voodoo Exam | Question Bank We have moved to a new website(www.irixtech.com) where you can now take mock exams online, come back & review your answers later, ask questions in our forums & SCJP questions ranging from SCJP 1.4 to SCJP 6.0, including these question banks & dumps from this site. Click here to be taken to our new website. This is the HTML version of Exam_3 as included in Voodoo Exam . Answers are available at the end of this page. The exam is also available as a database for Voodoo Exam . Click here & download the file called Exam_3.zip & add it to your Voodoo Exam . To learn how to add this file to Voodoo Exam see the ReadMe file that comes with the Voodoo Exam download . If you'd like to see your question's here download Voodoo Exam & add your own questions to it . Then send me the databases you'd have made & along with including your questions in my application I'll make a seperate page where your questions will be hosted . Sharing your knowledge can prove to be a boon for you as well as for the other folks out there . If you can't be bothered with any downloads but would still like to share your wisdom , then mail me . Most of the questions presented here are actual working codes that you can cut n' paste into your favourite editor . My personal opinion is that the more you code the sooner you'll get a hang of the concepts . So , don't get bugged by seeing around 10 - 12 lines of code , try to get a hang of visualizing things cause you do get a lot of code based questions in the cert . If you have any questions regarding the content of this question bank mail me . Your comments & suggestions will be highly appreciated .
1. Will the following code compile ? If yes , what is the output ? class Q019 { static Object obj ; String get ( ) { return null ; } public static void main ( String args [ ] ) { System . out . println ( ( new Q019 ( ) ) . get ( ) == ( Q019 . obj ) ) ; } };Options :
2. Consider the following declaration byte b = 127 ;Is the following valid - b >>= 2 ;Options :
3. Given the following class file , how can you get a reference to an object of type Inner ? class Outer { // some valid lines of code static class Inner { //some more valid lines of code } }Options :
4. Consider the code below . By making which of the changes listed below can we make the class compile with no errors at compile - time ? class A { private A ( ) { } A ( String str ) { } }; class B extends A { public static void main ( String args [ ] ) { System . out . println ( " Hello " ) ; } };Options :
5. Will the code given below compile ? If run with the following command line - java just - what is the output ? class Test{ public static void main ( String args [ ] ) { String str = args [ 0 ] ; switch ( str . equals ( " just " ) ) { case 1 : System . out . println ( " case 1 " ) ; break ; case 2 : System . out . println ( " case 2 " ) ; break ; default : break ; } } };eOptions :
6. Consider the following code . what is the result of compiling & executing C.java ? class A { } class B extends A { } class C extends B { static void doSomething ( A x , A y ) {System.out.print("AA");} static void doSomething ( A x , B y ) {System.out.print("AB");} static void doSomething ( B x , A y ) {System.out.print("BA");} static void doSomething ( B x , B y ) {System.out.print("BB");} static void doSomething ( C x , C y ) { System.out.println("CC");} public static void main(String[] args) { doSomething(null,null); } }Options :
7. Will the following code compile ? If yes , what is the output ? class Q013 { String str ; Q013 ( String str ) { System . out . print ( str ) ; } public static void main ( String ka [ ] ) { Q013 obj = new Q013 ( " Hello " ) ; System . out . print ( obj . str ) ; } }Options :
8. Consider that the following code compiles fine . What is the output ? class Q029 { public static void main ( String args [ ] ) { boolean b [ ] = new boolean[ 2 ] ; System . out . println ( b [ 1 ] ) ; } };Options :
9. Will the following code compile ? If yes , what is the output generated at runtime ? class Q022 { public static void main ( String ka [ ] ) { while ( false ) { System . out . println ( " Great " ) ; } } };Options :
10. By changing which line in the following code can you make it compile with no compile - time errors . class StatTest { class Int { static int x = 10 ; // ---> line 1 int y = 10 ; // ---> line 2 }; static class Inter { static int x = 10 ; // ---> line 3 int y = 10 ; // ---> line 4 }; };Options :
11. class Q05.java & Just.java both compile fine . What is the result of executing Q05.java ? class Just { int a = 10 ; Just ( ) { call ( ) ; } void call ( ) { System . out . print( "a = " + a + " ") ; } }; class Q05 extends Just { int b = 16 ; Q05 ( ) { call ( ) ; } void call ( ) { System.out.print( " b = " + b + " " ) ; } public static void main ( String args [ ] ) { new Q05 ( ) ; } }Options :
12. What is the result of compiling & executing the following code ? class Q06 { void Q06 ( ) { System . out . println ( " In Q06 " ) ; } public static void main ( String args [ ] ) { new Q06 ( ) ; System . out . println ( " Done " ) ; } };Options :
13. If the following code were to be present in a method ( in a class file ) what would be the output ? Byte b1 = new Byte("127"); if(b1.toString() == b1.toString()) System.out.println("True"); else System.out.println("False");Options :
14. Will the following code compile ? If yes what is the output generated ? class OuterTest { String id ; OuterTest ( ) { this . id = " Default " ; } OuterTest ( String id ) { this . id = id ; } class InnerTest extends OuterTest { void doSomething ( ) { System . out . println ( id ) ; } }; public static void main ( String args [ ] ) { OuterTest outer = new OuterTest ( " STP " ) ; InnerTest inner = outer . new InnerTest ( ) ; inner . doSomething ( ) ; } };Options :
15. Will the following code compile ? If yes what is the output ? class Q012 { Q012 ( int i ) { System . out . println ( i ) ; this . i = i ; } public static void main ( String ka [ ] ) { Q012 obj = new Q012 ( 10 ) ; } }Options :
16. Will the following code compile ? If yes , what is the output generated at runtime ? class Q006 { public static void main ( String args [ ] ) { boolean flag = false ; if ( flag = true ) { System . out . print ( " true " ) ; } if ( flag == false ) { System . out . print ( " false " ) ; } } };Options :
17. What will happen when you invoke the following method? void infiniteLoop ( ) { byte b = 1 ; while ( ++b > 0 ) ; System . out . println ( " Welcome to Java " ) ; }Options :
18. Will the following code compile ? If yes , what is the output ? class OuterTest { String id ; OuterTest ( ) { this . id = " Default " ; } OuterTest ( String id ) { this . id = id ; } class InnerTest extends OuterTest { void doSomething ( ) { System . out . println ( OuterTest . this . id ) ; } }; public static void main ( String args [ ] ) { OuterTest outer = new OuterTest ( " STP " ) ; InnerTest inner = outer . new InnerTest ( ) ; inner . doSomething ( ) ; } };Options :
19. Will the following code compile ? If yes , what is the output generated ? public class Q10 { public static void main ( String [ ] args ) { int i = 10 ; int j = 10 ; boolean b = false ; if( b = i == j ) // ---> line 1 System . out . println ( " True " ) ; else System . out . println ( " False " ) ; } }Options :
20. What is the output of the following code when compiled & executed ? class Q01 { public static void main ( String args [ ] ) { double d = -10 / 0.0 ; double e = -11 / 0.0 ; if ( d == e ) { System . out . println ( " d = e " ) ; } else System . out . println ( " d != e " ) ; } };Options :
21. The following code compiles fine . what is the output generated when the code is executed ? class Star { static { System . out . print ( " Static " ) ; } { System . out . print ( " Init " ) ; } Star ( ) { System . out . print ( " Const " ) ; } public static void main ( String args [ ] ) { System . out . print ( " main " ) ; } };Options :
22. What is the output of the following code ? class A{ static int i; A(){ ++i; } int get(){ return ++i; } }; class B extends A{ private B(){ i++; } int get(){ return ( i + 3); } }; class Q028 extends B{ public static void main(String ka[]){ Q028 obj = new Q028(); A ob = new A(); ob = (A)obj; System.out.println(ob.get()); } };Options :
23. Will the following code compile ? If yes , what is the output ? class Q015 { public String get ( int i ) { return null ; } public static void main ( String ka [ ] ) { Q015 obj = new Q015 ( ) ; Object i = obj . get ( 10 ) ; System . out . println ( i . toString ( ) ) ; } };Options :
24. What is the result of compiling & executing the following class ? class Q02 { public static void main ( String args [ ] ) { Double d = new Double ( " -10 / 0.0 " ) ; System . out . println ( d ) ; } };Options :
25. Will the following code compile ? If yes what is the output ? class Q04 { public static void main ( String args [ ] ) { double d = 10 ; double e = 10 ; if ( d . equals ( e ) ) { System . out . print ( " True " ) ; } else System . out . print ( " False " ) ; } };Options :
26. Will the following code compile ? If yes , what is the output ? class WhiteZombie { public static void main ( String args [ ] ) { int i = 2 , j = 3 , k = 5; String str = " + " , eq = " = "; System . out . println ( i + j + str + k + eq + ( i + j + k ) ) ; } };Options :
27. What is the output generated by the following code ? class Q03 { public static void main ( String args [ ] ) { Double a = new Double ( Double . NaN ) ; Double b = new Double ( Double . NaN ) ; if ( Double . NaN == Double . NaN ) { System . out . print ( " True " ) ; } else System . out . print ( " False " ) ; if ( a . equals ( b ) ) { System . out . print ( " True " ) ; } else System . out . print ( " False " ) ; } }Options :
28. Which of the following keywords can't be applied to a constructor ? Options :
29. Will the following code compile ? If yes , what is the output generated at runtime ? class Q024 { private String get ( String str ) { try { return str ; throw new Exception ( ) ; } catch ( Exception e ) { return null ; } } public static void main ( String peace [ ] ) { try { System . out . println ( ( new Q024 ( ) ) . get ( "Peace" ) ) ; } catch ( Exception e ) { System . out . println ( " Argh ! " ) ; } } };Options :
30. What is the result of compiling & executing InnerMet . java ? class InnerMet { public static void main ( String args [ ] ) { int x = 10 ; final int y = 10 ; class Inner { int g = x ; int r = y ; Inner ( ) { System . out . println ( " g = " + g + " & r = " + r ) ; } }; new Inner ( ) ; } };Options :
31. Will the output from the following two code snippets be any different ? Snippet 1 : for ( int i = 0 ; i < 5 ; i++ ) { System . out . println ( i ) ; } Snippet 2 : for ( int i = 0 ; i < 5 ; ++i ) { System . out . println ( i ) ; }Options :
32. Will the following code compile ? If yes , what is the output generated at runtime ? class Q023 { private String get ( String str ) { try { throw new Exception ( ) ; return str ; } catch ( Exception e ) { return null ; } } public static void main ( String peace [ ] ) { try { System . out . println ( ( new Q023 ( ) ) . get ( " Peace " ) ) ; } catch ( Exception e ) { System . out . println ( " Argh ! " ) ; } } };Options :
33. Will the following code compile ? If yes , what is the output & if not what is the compiler error ? class Test { static String raid ( ) { try { throw new Exception ( ) ; } catch ( Exception e ) { int i = 1 / 0 ; return " Error " ; } finally { return " Peace " ; } } public static void main ( String args [ ] ) { System . out . println ( raid ( ) ) ; } };Options :
34. What is the compiler error generated by the following piece of code or what is the output if any ? class Test { public static void main ( String args [ ] ) { int i = 1 ; if ( i = 2 ) { System . out . println ( " In if " ) ; } else System . out . println ( " In else " ) ; } };Options :
35. Will the following code compile ? If yes , what is the output generated at runtime ? class A { static int i ; private int get ( ) { return 1 ; } }; class B extends A { private int get ( ) { return 2 ; } }; class Q027 extends B { public static void main ( String ka [ ] ) { Q027 obj = new Q027 ( ) ; System . out . println ( obj . get ( ) ) ; } };Options :
|
© 2000-2002 Ashish Hareet |