

MCQOPTIONS
Saved Bookmarks
This section includes 61 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.
1. |
and given that all methods of class , including , throw an , which of these is true? |
A. | This program will compile successfully. |
B. | This program fails to compile due to an error at line 4. |
C. | This program fails to compile due to an error at line 6. |
D. | This program fails to compile due to an error at line 18. |
Answer» E. | |
2. |
Which four can be thrown using the throw statement? |
A. | 1, 2, 3 and 4 |
B. | 2, 3, 4 and 5 |
C. | 1, 4, 5 and 6 |
D. | 2, 4, 5 and 6 |
Answer» D. 2, 4, 5 and 6 | |
3. |
and given that and are both subclasses of , and further assuming this block of code is placed into a class, which statement is most true concerning this code? |
A. | The code will not compile. |
B. | Code output: Start Hello world File Not Found. |
C. | Code output: Start Hello world End of file exception. |
D. | Code output: Start Hello world Catch Here File not found. |
Answer» B. Code output: Start Hello world File Not Found. | |
4. |
What is the output of this program?
|
A. | -1 0 |
B. | 0 -1 |
C. | 0 |
D. | 1 |
E. | None of these |
Answer» B. 0 -1 | |
5. |
What is the output of this program?
|
A. | Welcome to |
B. | Interview Mania |
C. | Interview |
D. | Mania |
E. | Welcome to Interview Mania |
Answer» F. | |
6. |
What is the output of this program?
|
A. | First |
B. | Second |
C. | Interview Mania |
D. | Compilation Error |
E. | Runtime Error |
Answer» F. | |
7. |
What is the output of this program?
|
A. | Compilation Error |
B. | Runtime Error |
C. | First |
D. | Second |
E. | None of these |
Answer» C. First | |
8. |
What is the output of this program?
|
A. | First |
B. | Second |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» B. Second | |
9. |
What is the output of this program?
|
A. | Interview Mania |
B. | Finally Executed |
C. | Runtime Error |
D. | Compilation Error |
E. | Interview Mania Finally executed.. |
Answer» F. | |
10. |
What is the output of this program?
|
A. | Compilation Error |
B. | Runtime Error |
C. | Finally block executed... |
D. | All of above |
E. | None of these |
Answer» D. All of above | |
11. |
What is the output of this program?
|
A. | Compilation Error |
B. | Runtime Error |
C. | First |
D. | 11 |
E. | None of these |
Answer» D. 11 | |
12. |
What is the output of this program?
|
A. | Interview Mania |
B. | Finally executed... |
C. | Interview Mania Finally executed... |
D. | All of above |
E. | None of these |
Answer» D. All of above | |
13. |
What is the output of this program?
|
A. | Compilation Error |
B. | Runtime Error |
C. | Hello |
D. | Java |
E. | None of these |
Answer» E. None of these | |
14. |
What is the output of this program?
|
A. | Runtime Error |
B. | Compilation Error |
C. | First |
D. | Second |
E. | None of these |
Answer» C. First | |
15. |
What is the output of this program?
|
A. | 10 |
B. | 3 |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» D. Runtime Error | |
16. |
What is the output of this program?
|
A. | Newexception |
B. | Execution |
C. | Newexception working proper... |
D. | Runtime Error |
E. | None of these |
Answer» D. Runtime Error | |
17. |
What is the output of this program?
|
A. | NullPointerException |
B. | ArithmeticException |
C. | Second |
D. | First |
E. | Runtime Error |
Answer» F. | |
18. |
What is the output of this program?
|
A. | 6 |
B. | Compilation Error |
C. | Runtime Error |
D. | Catch block Executed... |
E. | None of these |
Answer» D. Catch block Executed... | |
19. |
What is the output of this program?
|
A. | User define Exception executed... |
B. | Execution |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» B. Execution | |
20. |
What is the output of this program?
|
A. | I MISS U ALWAYS... |
B. | I LOVE YOU |
C. | FOREVER... |
D. | I LOVE YOU FOREVER... |
E. | None of these |
Answer» E. None of these | |
21. |
What is the output of this program?
|
A. | welcome to |
B. | Interview Mania |
C. | Interview |
D. | Mania |
E. | None of these |
Answer» C. Interview | |
22. |
What is the output of this program?
|
A. | 1020304050 |
B. | 10203050 |
C. | 1020304050U |
D. | 20304050U |
E. | 304050U |
Answer» D. 20304050U | |
23. |
What is the output of this program?
|
A. | Compilation Error |
B. | 56789 |
C. | Runtime Error |
D. | 12345 |
E. | 56780 |
Answer» C. Runtime Error | |
24. |
What is the output of this program?
|
A. | Compilation Error |
B. | Rutime Error |
C. | TypeA |
D. | TypeB |
E. | None of these |
Answer» B. Rutime Error | |
25. |
What is the output of this program?
|
A. | ***** |
B. | *** |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» C. Compilation Error | |
26. |
What is the output of this program?
|
A. | 10U |
B. | 10 |
C. | U |
D. | U10 |
E. | None of these |
Answer» B. 10 | |
27. |
What is the output of this program?
|
A. | 50 |
B. | M |
C. | 50M |
D. | M50 |
E. | None of these |
Answer» D. M50 | |
28. |
What is the output of this program?
|
A. | 1121314151L |
B. | 112131 |
C. | 1121314151U |
D. | 112131451 |
E. | L1121314151 |
Answer» B. 112131 | |
29. |
What is the output of this program?
|
A. | 123455 |
B. | 123 |
C. | 12345 |
D. | 123450 |
E. | 120345 |
Answer» B. 123 | |
30. |
What is the output of this program?
|
A. | Love You |
B. | You Love |
C. | Love |
D. | You |
E. | None of these |
Answer» E. None of these | |
31. |
What is the output of this program?
|
A. | Interveiw |
B. | Mania |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» C. Compilation Error | |
32. |
What will be the result after the class Test execution?class A{public void doA(){B b = new B();b.dobB();System.out.print("doA");}}class B{public void dobB(){C c = new C();c.doC();System.out.print("doB");}}class C{public void doC(){if(true)throw new NullPointerException();System.out.print("doC");}}public class Test{public static void main(String args[]){try{A a = new A();a.doA();}catch(Exception ex){System.out.print("error");}}} |
A. | doCdoBdoA" is printed |
B. | doAdoBdoC" is printed |
C. | doBdoAerror" is printed |
D. | error" is printed |
E. | othing is printed |
Answer» E. othing is printed | |
33. |
Given the code. What is the result when this program is executed?public class Test{static int x[];static{x[0] = 1;}public static void main(String args[]){}} |
A. | rrayIndexOutOfBoundsException is thrown |
B. | xceptionInInitializerError is thrown |
C. | llegalStateException is thrown |
D. | tackOverflowException is thrown |
E. | one of these |
Answer» C. llegalStateException is thrown | |
34. |
Predict the output:public class Test{public static void main(String args[]){try{String arr[] = new String[10];arr = null;arr[0] = "one";System.out.print(arr[0]);}catch(Exception ex){System.out.print("exception");}catch(NullPointerException nex){System.out.print("null pointer exception");}}} |
A. | one" is printed. |
B. | exception" is printed. |
C. | null pointer exception" is printed. |
D. | ompilation fails saying NullPointerException has already been caught. |
E. | one of these |
Answer» E. one of these | |
35. |
Which of the below statement is/are true about Error?A. An Error is a subclass of Throwable.B. An Error is a subclass of Exception.C. Error indicates serious problems that a reasonable application should not try to catch.D. An Error is a subclass of IOException. |
A. | and D |
B. | and B |
C. | and C |
D. | and C |
E. | and D |
Answer» C. and C | |
36. |
What will be the result of executing the following code?public class Test{public void divide(int a, int b){try{int c = a / b;}catch(Exception e){System.out.print("Exception ");}finally{System.out.println("Finally");}public static void main(String args[]){Test t = new Test();t.divide(0,3);}} |
A. | rints out: Exception |
B. | rints out: Exception Finally |
C. | ompile with error |
D. | rints out: Finally |
E. | one of these |
Answer» E. one of these | |
37. |
What is the output for the below code ?import java.io.FileNotFoundException;class A{public void printName() throws FileNotFoundException{System.out.println("Value-A");}}class B extends A{public void printName() throws NullPointerException{System.out.println("Name-B");}}public class Test{public static void main (String[] args) throws Exception{A a = new B();a.printName();}} |
A. | alue-A |
B. | ompilation fails-Exception NullPointerException is not compatible with throws clause in A.printName() |
C. | ame-B |
D. | ompilation succeed but no output |
E. | one of these |
Answer» D. ompilation succeed but no output | |
38. |
What will be the result after compiling this code?class SuperClass{public int doIt(String str, Integer... data)throws Exception{String signature = "(String, Integer[])";System.out.println(str + " " + signature);return 1;}}public class Test extends SuperClass{public int doIt(String str, Integer... data){String signature = "(String, Integer[])";System.out.println("Overridden: " + str + " " +signature);return 0;}public static void main(String... args){SuperClass sb = new Test();sb.doIt("hello", 3);}} |
A. | verridden: hello (String, Integer[]) |
B. | ello (String, Integer[]) |
C. | ompilation fails |
D. | one of these |
Answer» D. one of these | |
39. |
What will be the output?class MyClass{public String test(){try{System.out.print("One");return ";}finally{System.out.print("Two");}}}public class Test{public static void main(String args[]){MyClass m =new MyClass();m.test();}} |
A. | ne |
B. | wo |
C. | ne Two |
D. | ompilation Error |
E. | one of these |
Answer» D. ompilation Error | |
40. |
public class Test{public static void main(String args[]){try{int a = Integer.parseInt("four");}}}Which exception could be handled by the catch block for above? |
A. | llegalStateException |
B. | umberFormatException |
C. | lassCastException |
D. | rrayIndexOutOfBoundsException |
E. | one of these |
Answer» C. lassCastException | |
41. |
What will be the output of the following piece of code:class Person{public void talk() {}}public class Test{public static void main(String args[]){Person p = null;try{p.talk();}catch(NullPointerException e){System.out.print("There is a NullPointerException. ");}catch(Exception e){System.out.print("There is an Exception. ");}System.out.print("Everything went fine. ");}} |
A. | here is a NullPointerException. Everything went fine. |
B. | here is a NullPointerException. |
C. | here is a NullPointerException. There is an Exception. |
D. | his code will not compile, because in Java there are no pointers. |
Answer» B. here is a NullPointerException. | |
42. |
Given the following piece of code:class SalaryCalculationException extends Exception{}class Person{public void calculateSalary() throws SalaryCalculationException{//...throw new SalaryCalculationException();//...}}class Company{public void paySalaries(){new Person().calculateSalary();}}Which of the following statements is correct?1. This code will compile without any problems.2. This code will compile if in method paySalaries() we return a boolean in stead of void.3. This code will compile if we add a try-catch block in paySalaries().4. This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries(). |
A. | and 4 |
B. | and 3 |
C. | and 4 |
D. | and 4 |
E. | and 2 |
Answer» E. and 2 | |
43. |
What is the output of the following program code?public class Test{public static void main(String args[]){try{int i;return;}catch(Exception e){System.out.print("inCatchBlock");}finally{System.out.println("inFinallyBlock");}}} |
A. | nCatchBlock |
B. | nCatchBlock inFinallyBlock |
C. | nFinallyBlock |
D. | he program will return without printing anything |
Answer» D. he program will return without printing anything | |
44. |
Which exception is thrown when an array element is accessed beyond the array size? |
A. | rrayElementOutOfBounds |
B. | rrayIndexOutOfBoundsException |
C. | rrayIndexOutOfBounds |
D. | one of these |
Answer» C. rrayIndexOutOfBounds | |
45. |
What happen in case of multiple catch blocks? |
A. | ither super or subclass can be caught first. |
B. | he superclass exception must be caught first. |
C. | he superclass exception cannot caught first. |
D. | one of these |
Answer» D. one of these | |
46. |
Which of the following blocks execute compulsorily whether exception is caught or not. |
A. | inally |
B. | atch |
C. | hrows |
D. | hrow |
Answer» B. atch | |
47. |
System.out.print("Start "); try { System.out.print("Hello world"); throw new FileNotFoundException(); } System.out.print(" Catch Here "); /* Line 7 */ catch(EOFException e) { System.out.print("End of file exception"); } catch(FileNotFoundException e) { System.out.print("File not found"); } and given that EOFException and FileNotFoundException are both subclasses of IOException, and further assuming this block of code is placed into a class, which statement is most true concerning this code? |
A. | The code will not compile. |
B. | Code output: Start Hello world File Not Found. |
C. | Code output: Start Hello world End of file exception. |
D. | Code output: Start Hello world Catch Here File not found. |
Answer» B. Code output: Start Hello world File Not Found. | |
48. |
What will be the output of the program? class Exc0 extends Exception { } class Exc1 extends Exc0 { } /* Line 2 */ public class Test { public static void main(String args[]) { try { throw new Exc1(); /* Line 9 */ } catch (Exc0 e0) /* Line 11 */ { System.out.println("Ex0 caught"); } catch (Exception e) { System.out.println("exception caught"); } } } |
A. | Ex0 caught |
B. | exception caught |
C. | Compilation fails because of an error at line 2. |
D. | Compilation fails because of an error at line 9. |
Answer» B. exception caught | |
49. |
public class ExceptionTest { class TestException extends Exception {} public void runTest() throws TestException {} public void test() /* Point X */ { runTest(); } } At Point X on line 5, which code is necessary to make the code compile? |
A. | No code is necessary. |
B. | throws Exception |
C. | catch ( Exception e ) |
D. | throws RuntimeException |
Answer» C. catch ( Exception e ) | |
50. |
public class MyProgram { public static void throwit() { throw new RuntimeException(); } public static void main(String args[]) { try { System.out.println("Hello world "); throwit(); System.out.println("Done with try block "); } finally { System.out.println("Finally executing "); } } } which answer most closely indicates the behavior of the program? |
A. | The program will not compile. |
B. | The program will print Hello world, then will print that a RuntimeException has occurred, then will print Done with try block, and then will print Finally executing. |
C. | The program will print Hello world, then will print that a RuntimeException has occurred, and then will print Finally executing. |
D. | The program will print Hello world, then will print Finally executing, then will print that a RuntimeException has occurred. |
Answer» E. | |