

MCQOPTIONS
Saved Bookmarks
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.
401. |
What is the length of the application box made by this program?
import java.awt.*; import java.applet.*; public class myapplet extends Applet { public void paint(Graphics g) { g.drawString("A Simple Applet", 20, 20); } } |
A. | 20 |
B. | 50 |
C. | 100 |
D. | System dependent |
Answer» B. 50 | |
402. |
What is the output of this program?
class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.setCharAt(1,x); System.out.println(s1); } } |
A. | Xello |
B. | Xxxxx |
C. | Hxllo |
D. | Hexlo |
Answer» D. Hexlo | |
403. |
What is the output of this program?
class Input_Output { public static void main(String args[]) throws IOException { char c; BufferedReader obj = new BufferedReader(new InputStreamReader(System.in)); do { c = (char) obj.read(); System.out.print(c); } while(c != ' ''); } } |
A. | abc |
B. | abcdef/ |
C. | abc def/ egh |
D. | abcqfghq |
Answer» B. abcdef/ | |
404. |
What is the output of this program?
import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdef"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 0, 3); int i; try { while((i = input2.read()) != -1) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } } |
A. | Abc |
B. | Abcd |
C. | Abcde |
D. | None of the mentioned |
Answer» E. | |
405. |
What is the output of this program?
class output { public static void main(String args[]) { char c[]={'a','1','b',' ','A','0']; for (int i = 0; i < 5; ++i) { if(Character.isDigit(c[i])) System.out.println(c[i]" is a digit"); if(Character.isWhitespace(c[i])) System.out.println(c[i]" is a Whitespace character"); if(Character.isUpperCase(c[i])) System.out.println(c[i]" is an Upper case Letter"); if(Character.isUpperCase(c[i])) System.out.println(c[i]" is a lower case Letter"); i = i + 3; } } } |
A. | a is a lower case Letter is White space character |
B. | b is a lower case Letter is White space characte |
C. | a is a lower case Letter A is a upper case Letter |
D. | a is a lower case Letter 0 is a digit |
Answer» B. b is a lower case Letter is White space characte | |
406. |
What is the output of this program?
class output { public static void main(String args[]) { String a="hello i love java"; System.out.println(indexof('i')+" "+indexof('o')+" "+lastIndexof('i')+" "+lastIndexof('o') )); } } |
A. | 6 4 6 9 |
B. | 5 4 5 9 |
C. | 7 8 8 9 |
D. | 4 3 6 9 |
Answer» B. 5 4 5 9 | |
407. |
What is the output of this program?
class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } |
A. | Hello |
B. | OlleH |
C. | HelloolleH |
D. | OlleHHello |
Answer» C. HelloolleH | |
408. |
What is the output of this program?
class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
A. | 2 2 |
B. | 3 3 |
C. | Runtime Error |
D. | Compilation Error |
Answer» E. | |
409. |
What is the output of this program?
final class A { int i; } class B extends A { int j; System.out.println(j + " " + i); } class inheritance { public static void main(String args[]) { B obj = new B(); obj.display(); } } |
A. | 2 2 |
B. | 3 3 |
C. | Runtime Error |
D. | Compilation Error |
Answer» E. | |
410. |
What is the output of this program?
class Alligator { public static void main(String[] args) { int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}}; int [][]y = x; System.out.println(y[2][1]); } } |
A. | 2 |
B. | 3 |
C. | 7 |
D. | Compilation Error |
Answer» D. Compilation Error | |
411. |
What is the output of this program?
class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class method_overriding { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation Error |
Answer» D. Compilation Error | |
412. |
What is the output of this program?
class Abc { public static void main(String[]args) { String[] elements = { "for", "tea", "too" }; String first = (elements.length > 0) ? elements[0]: null; } } |
A. | Compilation error |
B. | An exception is thrown at run time |
C. | The variable first is set to null |
D. | The variable first is set to elements[0]. |
Answer» E. | |
413. |
What is the output of this program?
class A { int i; public void display() { System.out.println(i); } } class B extends A { int j; public void display() { System.out.println(j); } } class Dynamic_dispatch { public static void main(String args[]) { B obj2 = new B(); obj2.i = 1; obj2.j = 2; A r; r = obj2; r.display(); } } |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» C. 3 | |
414. |
What is the output of this program?
class Output { public static void main(String args[]) { Object obj = new Object(); System.out.print(obj.getclass()); } } |
A. | Object |
B. | Class Object |
C. | Class java.lang.Object |
D. | Compilation Error |
Answer» D. Compilation Error | |
415. |
What is the output of this program?
class A { int i; int j; A() { i = 1; j = 2; } } class Output { public static void main(String args[]) { A obj1 = new A(); System.out.print(obj1.toString()); } } |
A. | True |
B. | False |
C. | String associated with obj1 |
D. | Compilation Error |
Answer» D. Compilation Error | |
416. |
Which two classes use the Shape class correctly?
A. public class Circle implements Shape { private int radius; } B. public abstract class Circle extends Shape { private int radius; } C. public class Circle extends Shape { private int radius; public void draw(); } D. public abstract class Circle implements Shape { private int radius; public void draw(); } E. public class Circle extends Shape { private int radius; public void draw() { /* code here */ } } F. public abstract class Circle implements Shape { private int radius; public void draw() { /* code here */ } } |
A. | B,E |
B. | A,C |
C. | C,E |
D. | T,H |
Answer» B. A,C | |
417. |
What is the output of this program?
class A { public int i; protected int j; } class B extends A { int j; void display() { super.j = 3; System.out.println(i + " " + j); } } class Output { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
A. | 1 2 |
B. | 2 1 |
C. | 1 3 |
D. | 3 1 |
Answer» B. 2 1 | |
418. |
What is the output of this program?
class A { int i; void display() { System.out.println(i); } } class B extends A { int j; void display() { System.out.println(j); } } class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | Compilation Error |
Answer» D. Compilation Error | |
419. |
What is the output of this program?
class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } |
A. | 2 2 |
B. | 3 3 |
C. | 2 3 |
D. | 3 2 |
Answer» D. 3 2 | |
420. |
What is the output of this program?
class A { public int i; public int j; A() { i = 1; j = 2; } } class B extends A { int a; B() { super(); } } class super_use { public static void main(String args[]) { B obj = new B(); System.out.println(obj.i + " " + obj.j) } } |
A. | 1 2 |
B. | 2 1 |
C. | Runtime Error |
D. | Compilation Error |
Answer» B. 2 1 | |
421. |
What is the output of this program?
class box { int width; int height; int length; int volume; void volume(int height, int length, int width) { volume = width*height*length; } } class Prameterized_method { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(3,2,1); System.out.println(obj.volume); } } |
A. | 0 |
B. | 1 |
C. | 6 |
D. | 25 |
Answer» D. 25 | |
422. |
What is the output of this program?
class equality { int x; int y; boolean isequal() { return(x == y); } } class Output { public static void main(String args[]) { equality obj = new equality(); obj.x = 5; obj.y = 5; System.out.println(obj.isequal()); } } |
A. | False |
B. | True |
C. | 0 |
D. | 1 |
Answer» C. 0 | |
423. |
What is the output of the following code?
class Compscibits { public void m1 (int i,float f) { System.out.println(" int float method"); } public void m1(float f,int i); { System.out.println("float int method"); } public static void main(String[]args) { Compscibits c=new Compscibits(); c.m1(20,20); } } |
A. | Int float method |
B. | Float int method |
C. | Compile time error |
D. | Run time error |
Answer» D. Run time error | |
424. |
What is the output of this program?
class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a, int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6); System.out.println(obj.x); } } |
A. | 5 |
B. | 6 |
C. | 7 |
D. | 8 |
Answer» D. 8 | |
425. |
What is the output of this program?
class overload { int x; int y; void add(int a) { x = a + 1; } void add(int a , int b) { x = a + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 0; obj.add(6, 7); System.out.println(obj.x); } } |
A. | 6 |
B. | 7 |
C. | 8 |
D. | 9 |
Answer» D. 9 | |
426. |
What is the output of this program?
class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } } class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x + " " + obj.y); } } |
A. | 3 3 |
B. | 2 3 |
C. | Runtime Error |
D. | Compilation Error |
Answer» D. Compilation Error | |
427. |
What is the output of this program?
class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } void print() { system.out.println(" " + y); } } class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x); obj.print(); } } |
A. | 2 3 |
B. | 3 3 |
C. | Runtime Error |
D. | Compilation Error |
Answer» C. Runtime Error | |
428. |
What is the output of this program?
class box { int width; int height; int length; int volume; box() { width = 5; height = 5; length = 6; } void volume() { volume = width*height*length; } } class constructor_output { public static void main(String args[]) { box obj = new box(); obj.volume(); System.out.println(obj.volume); } } |
A. | 100 |
B. | 150 |
C. | 200 |
D. | 250 |
Answer» C. 200 | |
429. |
What is the output of this program?
class Compsci { Compsci()throws IOException { } } class Bits extends Compsci { Bits() { } public static void main(String[]args) { } } |
A. | Compile time error |
B. | Run time error |
C. | Compile and runs fine |
D. | Unreported exception java.io.IOException in default constructor |
Answer» B. Run time error | |
430. |
What is the output of this program?
package pkg; class display { int x; void show() { if (x > 1) System.out.print(x + " "); } } class packages { public static void main(String args[]) { display[] arr=new display[3]; for(int i=0;i<3;i++) arr[i]=new display(); arr[0].x = 0; arr[1].x = 1; arr[2].x = 2; for (int i = 0; i < 3; ++i) arr[i].show(); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 0 1 2 |
Answer» D. 0 1 2 | |
431. |
What is the output of this program?
package pkg; class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.setCharAt(1, x); System.out.println(s1); } } |
A. | Xello |
B. | Xxxxx |
C. | Hxllo |
D. | Hexlo |
Answer» D. Hexlo | |
432. |
What is the output of this program?
package pkg; class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello World"); s1.insert(6 , "Good "); System.out.println(s1); } } |
A. | HelloGoodWorld |
B. | HellGoodoWorld |
C. | Compilation error |
D. | Runtime error |
Answer» E. | |
433. |
What is the output of this program?
interface calculate { void cal(int item); } class displayA implements calculate { int x; public void cal(int item) { x = item * item; } } class displayB implements calculate { int x; public void cal(int item) { x = item / item; } } class interfaces { public static void main(String args[]) { displayA arr1 = new displayA; displayB arr2 = new displayB; arr1.x = 0; arr2.x = 0; arr1.cal(2); arr2.cal(2); System.out.print(arr1.x + " " + arr2.x); } } |
A. | 0 0 |
B. | 2 2 |
C. | 4 1 |
D. | 1 4 |
Answer» D. 1 4 | |
434. |
What is the output of this program?
interface calculate { void cal(int item); } class display implements calculate { int x; public void cal(int item) { x = item * item; } } class interfaces { public static void main(String args[]) { display arr = new display; arr.x = 0; arr.cal(2); System.out.print(arr.x); } } |
A. | 0 |
B. | 2 |
C. | 4 |
D. | None of the mentioned |
Answer» D. None of the mentioned | |
435. |
What is the output of this program?
public class Bits { 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 | |
436. |
What is the output of this program?
|
A. | 0 |
B. | 1 |
C. | Compilation Error |
D. | Runtime Error |
Answer» C. Compilation Error | |
437. |
What is the output of this program?
class exception_handling { public static void main(String args[]) { try { throw new NullPointerException ("Hello"); } catch(ArithmeticException e) { System.out.print("B"); } } } |
A. | A |
B. | B |
C. | Compilation Error |
D. | Runtime Error |
Answer» E. | |
438. |
What is the output of this program?
public class San { public static void main(String args[]) { try { System.out.print("Hello world "); } finally { System.out.println("Finally executing "); } } } |
A. | The program will not compile because no exceptions are specified |
B. | The program will not compile because no catch clauses are specified |
C. | Hello world |
D. | Hello world Finally executing |
Answer» E. | |
439. |
What is the output of this program?
class exception_handling { public static void main(String args[]) { try { int a, b; b = 0; a = 5 / b; System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } finally { System.out.print("C"); } } } |
A. | A |
B. | B |
C. | AC |
D. | BC |
Answer» E. | |
440. |
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); } catch(ArithmeticException e) { System.out.print("0"); } System.out.print(sum); } } |
A. | 0 |
B. | 05 |
C. | Compilation Error |
D. | Runtime Error |
Answer» D. Runtime Error | |
441. |
What is the output of this program?
class exception_handling { public static void main(String args[]) { try { int a = 1; int b = 10 / a; try { if (a == 1) a = a / a - a; if (a == 2) { int c[] = {1}; c[8] = 9; } } finally { System.out.print("A"); } } catch (Exception e) { System.out.println("B"); } } } |
A. | A |
B. | B |
C. | AB |
D. | BA |
Answer» B. B | |
442. |
What is the output of this program? Note: Execution command line: $ java exception_handling one two
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. | Compilation Error |
D. | Runtime Error |
Answer» D. Runtime Error | |
443. |
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"); } } } |
A. | Hello |
B. | World |
C. | HelloWOrld |
D. | Compilation Error |
Answer» E. | |
444. |
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"); } finally { System.out.print("World"); } } } |
A. | Hello |
B. | World |
C. | HelloWorld |
D. | Compilation Error |
Answer» D. Compilation Error | |
445. |
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"); } finally { System.out.print("World"); } } } |
A. | Hello |
B. | World |
C. | HelloWorld |
D. | WorldWorld |
Answer» E. | |
446. |
What is the output of this program?
class exception_handling { public static void main(String args[]) { try { throw new NullPointerException ("Hello"); System.out.print("A"); } catch(ArithmeticException e) { System.out.print("B"); } } } |
A. | A |
B. | B |
C. | Compilation Error |
D. | Runtime Error |
Answer» E. | |
447. |
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(Exception e) { System.out.print("Exception"); } } } |
A. | 3 |
B. | Exception |
C. | Runtime Error |
D. | Compilation Error |
Answer» C. Runtime Error | |
448. |
What is the output of this program?Note : Execution command line : $ java exception_handling one
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. | Compilation Error |
D. | Runtime Error |
Answer» D. Runtime Error | |
449. |
What will be the output of the program?
public class Test { public static void aMethod() throws Exception { try /* Line 5 */ { throw new Exception(); /* Line 7 */ } finally /* Line 9 */ { System.out.print("finally "); /* Line 11 */ } } public static void main(String args[]) { try { aMethod(); } catch (Exception e) /* Line 20 */ { System.out.print("exception "); } System.out.print("finished"); /* Line 24 */ } } |
A. | Finally |
B. | Exception finished |
C. | Finally exception finished |
D. | Compilation fails |
Answer» D. Compilation fails | |
450. |
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 | |