Explore topic-wise MCQs in General Awareness.

This section includes 1698 Mcqs, each offering curated multiple-choice questions to sharpen your General Awareness knowledge and support exam preparation. Choose a topic below to get started.

451.

What will be the output of the program? public class MyProgram { public static void main(String args[]) { try { System.out.print("Hello world "); } finally { System.out.println("Finally executing "); } } }

A. Nothing. The program will not compile because no exceptions are specified.
B. Nothing. The program will not compile because no catch clauses are specified.
C. Hello world.
D. Hello world Finally executing
Answer» E.
452.

What will be the output of the program? public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( "Finally" ); } } }

A. Finally
B. Compilation fails.
C. The code runs with no output.
D. An exception is thrown at runtime.
Answer» B. Compilation fails.
453.

What will be the output of the program? try { int x = 0; int y = 5 / x; } catch (Exception e) { System.out.println("Exception"); } catch (ArithmeticException ae) { System.out.println(" Arithmetic Exception"); } System.out.println("finished");

A. Finished
B. Exception
C. Compilation fails.
D. Arithmetic Exception
Answer» D. Arithmetic Exception
454.

What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (Exception ex) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } public static void badMethod() { throw new Error(); /* Line 22 */ } }

A. ABCD
B. Compilation fails.
C. C is printed before exiting with an error message.
D. BC is printed before exiting with an error message.
Answer» D. BC is printed before exiting with an error message.
455.

What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (RuntimeException ex) /* Line 10 */ { System.out.print("B"); } catch (Exception ex1) { System.out.print("C"); } finally { System.out.print("D"); } System.out.print("E"); } public static void badMethod() { throw new RuntimeException(); } }

A. BD
B. BCD
C. BDE
D. BCDE
Answer» D. BCDE
456.

What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); System.out.print("A"); } catch (Exception ex) { System.out.print("B"); } finally { System.out.print("C"); } System.out.print("D"); } public static void badMethod() {} }

A. AC
B. BC
C. ACD
D. ABCD
Answer» D. ABCD
457.

What will be the output of the program? public class RTExcept { public static void throwit () { System.out.print("throwit "); throw new RuntimeException(); } public static void main(String [] args) { try { System.out.print("hello "); throwit(); } catch (Exception re ) { System.out.print("caught "); } finally { System.out.print("finally "); } System.out.println("after "); } }

A. Hello throwit caught
B. Compilation fails
C. Hello throwit RuntimeException caught after
D. Hello throwit caught finally after
Answer» E.
458.

What will be the output of the program? public class X { public static void main(String [] args) { try { badMethod(); /* Line 7 */ System.out.print("A"); } catch (Exception ex) /* Line 10 */ { System.out.print("B"); /* Line 12 */ } finally /* Line 14 */ { System.out.print("C"); /* Line 16 */ } System.out.print("D"); /* Line 18 */ } public static void badMethod() { throw new RuntimeException(); } }

A. AB
B. BC
C. ABC
D. BCD
Answer» E.
459.

Given that all methods of class FileOutputStream, including close(), throw an IOException, which of these is true? import java.io.*; public class MyProgram { public static void main(String args[]) { FileOutputStream out = null; try { out = new FileOutputStream("test.txt"); out.write(122); } catch(IOException io) { System.out.println("IO Error."); } finally { out.close(); } } }

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.
460.

Which answer most closely indicates the behavior of the program? 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 "); } } }

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.
461.

At Point X on line 5, which code is necessary to make the code compile? public class ExceptionTest { class TestException extends Exception {} public void runTest() throws TestException {} public void test() /* Point X */ { runTest(); } }

A. No code is necessary.
B. Throws Exception
C. Catch ( Exception e )
D. Throws RuntimeException
Answer» C. Catch ( Exception e )
462.

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? 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"); }

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.
463.

Which four can be thrown using the throw statement? 1. Error 2. Event 3. Object 4. Throwable 5. Exception 6. RuntimeException

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
464.

What is the output of this program? class Myexception extends Exception { int detail; Myexception(int a) { detail = a; } public String toString() { return "detail"; } } class Output { static void compute (int a) throws Myexception { throw new Myexception(a); } public static void main(String args[]) { try { compute(3); } catch(Myexception e) { System.out.print("Exception"); } } }

A. 3
B. Exception
C. Runtime Error
D. Compilation Error
Answer» C. Runtime Error
465.

What is the output of this program? class Myexception extends Exception { int detail; Myexception(int a) { detail = a; } public String toString() { return "detail"; } } class Output { static void compute (int a) throws Myexception { throw new Myexception(a); } public static void main(String args[]) { try { compute(3); } catch(DevideByZeroException e) { System.out.print("Exception"); } } }

A. 3
B. Exception
C. Runtime Error
D. Compilation Error
Answer» D. Compilation Error
466.

What is the output of this program? class exception_handling { public static void main(String args[]) { try { System.out.print("Hello" + " " + 1 / 0); } finally { System.out.print("World"); } } }

A. Hello
B. World
C. Compilation Error
D. First Exception then World
Answer» E.
467.

What is the output of this program? class exception_handling { public static void main(String args[]) { try { int i, sum; sum = 10; for (i = -1; i < 3 ;++i) { sum = (sum / i); System.out.print(i); } } catch(ArithmeticException e) { System.out.print("0"); } } }

A. -1
B. 0
C. -10
D. -101
Answer» D. -101
468.

What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a = args.length; int b = 10 / a; System.out.print(a); try { if (a == 1) a = a / a - a; if (a == 2) { int []c = {1}; c[8] = 9; } } catch (ArrayIndexOutOfBoundException e) { System.out.println("TypeA"); } catch (ArithmeticException e) { System.out.println("TypeB"); } } } }

A. TypeA
B. TypeB
C. Compile Time Error
D. 0TypeB
Answer» D. 0TypeB
469.

What is the output of this program? class exception_handling { public static void main(String args[]) { try { System.out.print("A"); throw new NullPointerException ("Hello"); } catch(ArithmeticException e) { System.out.print("B"); } } }

A. A
B. B
C. Hello
D. Runtime Exception
Answer» E.
470.

What is the output of this program? class Output { public static void main(String args[]) { try { int a = 0; int b = 5; int c = b / a; System.out.print("Hello"); } catch(Exception e) { System.out.print("World"); } } }

A. Hello
B. World
C. HelloWOrld
D. Compilation Error
Answer» C. HelloWOrld
471.

What is the output of this program? class Output { public static void main(String args[]) { try { int a = 0; int b = 5; int c = a / b; System.out.print("Hello"); } catch(Exception e) { System.out.print("World"); } } }

A. Hello
B. World
C. HelloWOrld
D. Compilation Error
Answer» B. World
472.

What is the output of below code snippet? class A { } enum Enums extends A { ABC, BCD, CDE, DEF; }

A. Runtime Error
B. Compilation Error
C. It runs successfully
D. EnumNotDefined Exception
Answer» C. It runs successfully
473.

What is the output of below code snippet? enum Levels { private TOP, public MEDIUM, protected BOTTOM; }

A. Runtime Error
B. EnumNotDefined Exception
C. It runs successfully
D. Compilation Error
Answer» E.
474.

What is the output of below code snippet? enum Enums { A, B, C; private Enums() { System.out.println(10); } } public class MainClass { public static void main(String[] args) { Enum en = Enums.B; } }

A. 0.009999999999999998 0.01
B. 0.01 0.009999999999999998
C. 0.01 0.01
D. 0.009999999999999998 0.009999999999999998
Answer» B. 0.01 0.009999999999999998
475.

What is the output of below code snippet? public class AddDemo { public static void main(String args[]) { BigDecimal b = new BigDecimal("23.43"); BigDecimal br = new BigDecimal("24"); BigDecimal bres = b.add(new BigDecimal("450.23")); System.out.println("Add: "+bres); MathContext mc = new MathContext(2, RoundingMode.DOWN); BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc); System.out.println("Add using MathContext: "+bdecMath); } }

A. Compilation failure
B. Add: 684.66 Add using MathContext: 6.8E+2
C. Runtime exception
D. Add 6.8E+2 Add using MathContext: 684.66
Answer» C. Runtime exception
476.

What will be the output of the program? Note: The command-line invocation is > java CommandArgsTwo 1 2 3 public class CommandArgsTwo { public static void main(String [] argh) { int x; x = argh.length; for (int y = 1; y <= x; y++) { System.out.print(" " + argh[y]); } } }

A. 0 1 2
B. 1 2 3
C. 0 0 0
D. An exception is thrown at runtime
Answer» E.
477.

In the given program, how many lines of output will be produced? public class Test { public static void main(String [] args) { int [] [] [] x = new int [3] [] []; int i, j; x[0] = new int[4][]; x[1] = new int[2][]; x[2] = new int[5][]; for (i = 0; i < x.length; i++) { for (j = 0; j < x[i].length; j++) { x[i][j] = new int [i + j + 1]; System.out.println("size = " + x[i][j].length); } } } }

A. 7
B. 9
C. 11
D. 13
Answer» D. 13
478.

What is the output of this program? class Output { public static void main(String args[]) { Double i = new Double(257.5); boolean x = i.isNaN(); System.out.print(x); } }

A. True
B. False
C. 0
D. 1
Answer» C. 0
479.

What is the output of this program? class Output { public static void main(String args[]) { Double i = new Double(257.578); int x = i.intValue(); System.out.print(x); } }

A. 0
B. 1
C. 256
D. 257
Answer» E.
480.

What is the output of this program? import java.io.*; class files { public static void main(String args[]) { File obj = new File("/java/system"); System.out.print(obj.getAbsolutePath()); } }

A. Java
B. System
C. Java/system
D. java system
Answer» E.
481.

What is the output of this program? import java.io.*; class files { public static void main(String args[]) { File obj = new File("/java/system"); System.out.print(obj.canWrite()); System.out.print(" " + obj.canRead()); } }

A. True false
B. False true
C. True true
D. False false
Answer» E.
482.

What is the output of this program? import java.io.*; class files { public static void main(String args[]) { File obj = new File("/java/system"); System.out.print(obj.getParent()); System.out.print(" " + obj.isFile()); } }

A. Java true
B. Java false
C. Java false
D. Java true
Answer» D. Java true
483.

What is the output of this program? Note: inputoutput.java is stored in the disk. import java.io.*; class filesinputoutput { public static void main(String args[]) { InputStream obj = new FileInputStream("inputoutput.java"); System.out.print(obj.available()); } }

A. True
B. False
C. Prints number of bytes in file
D. Prints number of characters in the file
Answer» D. Prints number of characters in the file
484.

What is the output of this program? class Output { public static void main(String args[]) { Double y = new Double(257.57812); Double i = new Double(257.578123456789); try { int x = i.compareTo(y); System.out.print(x); } catch(ClassCastException e) { System.out.print("Exception"); } } }

A. 0
B. 1
C. Exception
D. None of the mentioned
Answer» C. Exception
485.

What is the output of this program? import java.io.*; class files { public static void main(String args[]) { File obj = new File("/java/system"); System.out.print(obj.getName()); } }

A. Java
B. System
C. Java/system
D. /java/system
Answer» C. Java/system
486.

What will be the output of the program? public class Test { public static void main(String[] args) { final StringBuffer a = new StringBuffer(); final StringBuffer b = new StringBuffer(); new Thread() { public void run() { System.out.print(a.append("A")); synchronized(b) { System.out.print(b.append("B")); } } }.start(); new Thread() { public void run() { System.out.print(b.append("C")); synchronized(a) { System.out.print(a.append("D")); } } }.start(); } }

A. ACCBAD
B. ABBCAD
C. CDDACB
D. Indeterminate output
Answer» E.
487.

What will be the output of the program? 1. A 2. B 3. C 4. D String s = "hello"; Object o = s; if( o.equals(s) ) { System.out.println("A"); } else { System.out.println("B"); } if( s.equals(o) ) { System.out.println("C"); } else { System.out.println("D"); }

A. 1 and 3
B. 2 and 4
C. 3 and 4
D. 1 and 2
Answer» B. 2 and 4
488.

What will be the output of the program (in jdk1.6 or above)? public class BoolTest { public static void main(String [] args) { Boolean b1 = new Boolean("false"); boolean b2; b2 = b1.booleanValue(); if (!b2) { b2 = true; System.out.print("x "); } if (b1 & b2) /* Line 13 */ { System.out.print("y "); } System.out.println("z"); } }

A. Z
B. x z
C. y z
D. Compilation fails.
Answer» C. y z
489.

What will be the output of the program? public class Test138 { public static void stringReplace (String text) { text = text.replace ('j' , 'c'); /* Line 5 */ } public static void bufferReplace (StringBuffer text) { text = text.append ("c"); /* Line 9 */ } public static void main (String args[]) { String textString = new String ("java"); StringBuffer textBuffer = new StringBuffer ("java"); /* Line 14 */ stringReplace(textString); bufferReplace(textBuffer); System.out.println (textString + textBuffer); } }

A. Java
B. Javac
C. Javajavac
D. Compile error
Answer» D. Compile error
490.

What will be the output of the program? String d = "bookkeeper"; d.substring(1,7); d = "w" + d; d.append("woo"); /* Line 4 */ System.out.println(d);

A. Wookkeewoo
B. Wbookkeeper
C. Wbookkeewoo
D. Compilation fails.
Answer» E.
491.

What will be the output of the program? class Tree { } class Pine extends Tree { } class Oak extends Tree { } public class Forest1 { public static void main (String [] args) { Tree tree = new Pine(); if( tree instanceof Pine ) System.out.println ("Pine"); else if( tree instanceof Tree ) System.out.println ("Tree"); else if( tree instanceof Oak ) System.out.println ( "Oak" ); else System.out.println ("Oops "); } }

A. Pine
B. Tree
C. Forest
D. Oops
Answer» B. Tree
492.

What will be the output of the program? String a = "ABCD"; String b = a.toLowerCase(); b.replace('a','d'); b.replace('b','c'); System.out.println(b);

A. Abcd
B. ABCD
C. Dccd
D. Dcba
Answer» B. ABCD
493.

How many String objects have been created? String x = new String("xyz"); String y = "abc"; x = x + y;

A. 2
B. 3
C. 4
D. 5
Answer» D. 5
494.

What will be the output of the program? public class ExamQuestion6 { static int x; boolean catch() { x++; return true; } public static void main(String[] args) { x=0; if ((catch() | catch()) || catch()) x++; System.out.println(x); } }

A. 1
B. 2
C. 3
D. Compilation Fails
Answer» E.
495.

What is the output of this program? import java.lang.reflect.*; class Additional_packages { public static void main(String args[]) { try { Class c = Class.forName("java.awt.Dimension"); Constructor constructors[] = c.getConstructors(); for (int i = 0; i < constructors.length; i++) System.out.println(constructors[i]); } catch (Exception e) { System.out.print("Exception"); } } }

A. Program prints all the constructors of java.awt.Dimension package
B. Program prints all the possible constructors of class Class
C. Program prints Exception
D. Runtime Error
Answer» D. Runtime Error
496.

What is the output of this program? class static_out { static int x; static int y; void add(int a, int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } }

A. 7 7.4
B. 6 6.4
C. 7 9
D. 9 7
Answer» C. 7 9
497.

What is the output of this program? class static_out { static int x; static int y; void add(int a , int b) { x = a + b; y = x + b; } } class static_use { public static void main(String args[]) { static_out obj1 = new static_out(); static_out obj2 = new static_out(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); System.out.println(obj1.x + " " + obj2.y); } }

A. 7 7
B. 6 6
C. 7 9
D. 9 7
Answer» D. 9 7
498.

What is the output of this program? class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } }

A. 1 2
B. 1 2 3
C. 1 2 3 4
D. 1 2 3 4 5
Answer» C. 1 2 3 4
499.

What is the output of this program? class Output { public static void main(String args[]) { int a1[] = new int[10]; int a2[] = {1, 2, 3, 4, 5}; System.out.println(a1.length + " " + a2.length); } }

A. 10 5
B. 5 10
C. 0 10
D. 0 5
Answer» B. 5 10
500.

What is the output of this program? class box { int width; int height; int length; int volume; void volume() { volume = width * height * length; } void volume(int x) { volume = x; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(5); System.out.println(obj.volume); } }

A. 0
B. 5
C. 25
D. 26
Answer» C. 25