

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.
501. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "hello"; String obj1 = "world"; String obj2 = "hello"; System.out.println(obj.equals(obj1) + " " + obj.equals(obj2)); } } |
A. | False false |
B. | True true |
C. | True false |
D. | False true |
Answer» E. | |
502. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.length()); } } |
A. | Hello hello |
B. | World world |
C. | Hello world |
D. | World hello |
Answer» D. World hello | |
503. |
What is the output of this program? class Output { static void main(String args[]) { int x , y = 1; x = 10; if(x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } |
A. | 1 |
B. | 2 |
C. | Runtime Error |
D. | Compilation Error |
Answer» E. | |
504. |
What is the output of this program? class area { int width; int length; int height; area() { width = 5; length = 6; height = 1; } void volume() { volume = width * height * length; } } class cons_method { public static void main(String args[]) { area obj = new area(); obj.volume(); System.out.println(obj.volume); } } |
A. | 0 |
B. | 1 |
C. | 25 |
D. | 30 |
Answer» E. | |
505. |
What is the output of this program? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.fact(5)); } } |
A. | 24 |
B. | 30 |
C. | 120 |
D. | 720 |
Answer» D. 720 | |
506. |
What is the output of this program? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.fact(1)); } } |
A. | 1 |
B. | 30 |
C. | 120 |
D. | Runtime Error |
Answer» B. 30 | |
507. |
Which statement, inserted at line 10, creates an instance of Bar? class Foo { class Bar{ } } class Test { public static void main (String [] args) { Foo f = new Foo(); /* Line 10: Missing statement ? */ } } |
A. | Foo.Bar b = new Foo.Bar(); |
B. | Foo.Bar b = f.new Bar(); |
C. | Bar b = new f.Bar(); |
D. | Bar b = f.new Bar(); |
Answer» C. Bar b = new f.Bar(); | |
508. |
What is the output of this program? class recursion { int fact(int n) { int result; if (n == 1) return 1; result = fact(n - 1) * n; return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.fact(6)); } } |
A. | 1 |
B. | 30 |
C. | 120 |
D. | 720 |
Answer» E. | |
509. |
Which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class? public class MyOuter { public static class MyInner { public static void foo() { } } } |
A. | MyOuter.MyInner m = new MyOuter.MyInner(); |
B. | MyOuter.MyInner mi = new MyInner(); |
C. | MyOuter m = new MyOuter(); MyOuter.MyInner mi = m.new MyOuter.MyInner(); |
D. | MyInner mi = new MyOuter.MyInner(); |
Answer» B. MyOuter.MyInner mi = new MyInner(); | |
510. |
Which one create an anonymous inner class from within class Bar? class Boo { Boo(String s) { } Boo() { } } class Bar extends Boo { Bar() { } Bar(String s) {super(s);} void zoo() { // insert code here } } |
A. | Boo f = new Boo(24) { }; |
B. | Boo f = new Bar() { }; |
C. | Bar f = new Boo(String s) { }; |
D. | Boo f = new Boo.Bar(String s) { }; |
Answer» C. Bar f = new Boo(String s) { }; | |
511. |
What will be the output of the program? public class Foo { Foo() { System.out.print("foo"); } class Bar { Bar() { System.out.print("bar"); } public void go() { System.out.print("hi"); } } /* class Bar ends */ public static void main (String [] args) { Foo f = new Foo(); f.makeBar(); } void makeBar() { (new Bar() {}).go(); } }/* class Foo ends */ |
A. | Compilation fails. |
B. | An error occurs at runtime. |
C. | It prints "foobarhi" |
D. | It prints "barhi" |
Answer» D. It prints "barhi" | |
512. |
What will be the output of the program? public class HorseTest { public static void main (String [] args) { class Horse { public String name; /* Line 7 */ public Horse(String s) { name = s; } } /* class Horse ends */ Object obj = new Horse("Zippo"); /* Line 13 */ Horse h = (Horse) obj; /* Line 14 */ System.out.println(h.name); } } /* class HorseTest ends */ |
A. | An exception occurs at runtime at line 10. |
B. | It prints "Zippo". |
C. | Compilation fails because of an error on line 7. |
D. | Compilation fails because of an error on line 13. |
Answer» C. Compilation fails because of an error on line 7. | |
513. |
What will be the output of the program? public class TestObj { public static void main (String [] args) { Object o = new Object() /* Line 5 */ { public boolean equals(Object obj) { return true; } } /* Line 11 */ System.out.println(o.equals("Fred")); } } |
A. | It prints "true". |
B. | It prints "Fred". |
C. | An exception occurs at runtime. |
D. | Compilation fails |
Answer» E. | |
514. |
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 | |
515. |
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 | |
516. |
Which of these is a correct statement about args in this line of code?public static void main(String args[]) |
A. | Args is a String |
B. | Args is a Character |
C. | Args is an array of String |
D. | Args in an array of Character |
Answer» D. Args in an array of Character | |
517. |
What would be the output of following snippet, if attempted to compile and execute? class abc { public static void main(String args[]) { if(args.length>0) System.out.println(args.length); } } |
A. | The snippet compiles, runs and prints 0 |
B. | The snippet compiles, runs and prints 1 |
C. | The snippet does not compile |
D. | The snippet compiles and runs but does not print anything |
Answer» E. | |
518. |
What is the output of this program? class recursion { int func (int n) { int result; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(12)); } } |
A. | 0 |
B. | 1 |
C. | Compilation Error |
D. | Runtime Error |
Answer» E. | |
519. |
After line 11 runs, how many objects are eligible for garbage collection? class X2 { public X2 x; public static void main(String [] args) { X2 x2 = new X2(); /* Line 6 */ X2 x3 = new X2(); /* Line 7 */ x2.x = x3; x3.x = x2; x2 = new X2(); x3 = x2; /* Line 11 */ doComplexStuff(); } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» D. 3 | |
520. |
What is the output of this program? class recursion { int func (int n) { int result; if (n == 1) return 1; result = func (n - 1); return result; } } class Output { public static void main(String args[]) { recursion obj = new recursion() ; System.out.print(obj.func(5)); } } |
A. | 0 |
B. | 1 |
C. | 120 |
D. | None of the mentioned |
Answer» C. 120 | |
521. |
What is the output of this program? class box { int width; int height; int length; int volume; void volume() { volume = width*height*length; } } class Output { public static void main(String args[]) { box obj = new box(); obj.height = 1; obj.length = 5; obj.width = 5; obj.volume(); System.out.println(obj.volume); } } |
A. | 0 |
B. | 1 |
C. | 25 |
D. | 26 |
Answer» D. 26 | |
522. |
What is the output of this program? class access { public int x; static int y; void cal(int a, int b) { x += a ; y += b; } } class static_specifier { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.y = 0; obj1.cal(1, 2); obj2.x = 0; obj2.cal(2, 3); System.out.println(obj1.x + " " + obj2.y); } } |
A. | 1 2 |
B. | 2 3 |
C. | 3 2 |
D. | 1 5 |
Answer» E. | |
523. |
What is the output of this program? class access { static int x; void increment() { x++; } } class static_use { public static void main(String args[]) { access obj1 = new access(); access obj2 = new access(); obj1.x = 0; obj1.increment(); obj2.increment(); System.out.println(obj1.x + " " + obj2.x); } } |
A. | 1 2 |
B. | 1 1 |
C. | 2 2 |
D. | Compilation Error |
Answer» D. Compilation Error | |
524. |
What is the output of this program? class string_demo { public static void main(String args[]) { String obj = "I" + "like" + "Java"; System.out.println(obj); } } |
A. | I |
B. | Like |
C. | Java |
D. | IlikeJava |
Answer» E. | |
525. |
What is the output of this program? class string_class { public static void main(String args[]) { String obj = "I LIKE JAVA"; System.out.println(obj.charAt(3)); } } |
A. | I |
B. | L |
C. | K |
D. | E |
Answer» B. L | |
526. |
What is the output of this program? class area { int width; int length; int volume; area() { width=5; length=6; } void volume() { volume = width*length*height; } } class cons_method { public static void main(String args[]) { area obj = new area(); obj.volume(); System.out.println(obj.volume); } } |
A. | 0 |
B. | 1 |
C. | 30 |
D. | Error |
Answer» E. | |
527. |
In the below code, which call to sum() method is appropriate? class Output { public static int sum(int ...x) { return; } static void main(String args[]) { sum(10); sum(10,20); sum(10,20,30); sum(10,20,30,40); } } |
A. | Only sum(10) |
B. | Only sum(10,20) |
C. | Only sum(10) & sum(10,20) |
D. | All of the mentioned |
Answer» E. | |
528. |
What is the output of this program? class area { int width; int length; int area; void area(int width, int length) { this.width = width; this.length = length; } } class Output { public static void main(String args[]) { area obj = new area(); obj.area(5 , 6); System.out.println(obj.length + " " + obj.width); } } |
A. | 0 0 |
B. | 5 6 |
C. | 6 5 |
D. | 5 5 |
Answer» D. 5 5 | |
529. |
What is the output of this program? class box { int width; int height; int length; int volume; void finalize() { volume = width*height*length; System.out.println(volume); } protected void volume() { volume = width*height*length; System.out.println(volume); } } class Output { public static void main(String args[]) { box obj = new box(); obj.width=5; obj.height=5; obj.length=6; obj.volume(); } } |
A. | 150 |
B. | 200 |
C. | Run time error |
D. | Compilation error |
Answer» B. 200 | |
530. |
What is the output of this program? class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x = 0; this.y = 0; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int a = 2; double b = 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + " " + obj.y); } } |
A. | 6 6 |
B. | 6.4 6.4 |
C. | 6.4 6 |
D. | 4 6.4 |
Answer» E. | |
531. |
What is the output of this program? class test { int a; int b; void meth(int i , int j) { i *= 2; j /= 2; } } class Output { public static void main(String args[]) { test obj = new test(); int a = 10; int b = 20; obj.meth(a , b); System.out.println(a + " " + b); } } |
A. | 10 20 |
B. | 20 10 |
C. | 20 40 |
D. | 40 20 |
Answer» B. 20 10 | |
532. |
What is the output of this program? class test { int a; int b; test(int i, int j) { a = i; b = j; } void meth(test o) { o.a *= 2; O.b /= 2; } } class Output { public static void main(String args[]) { test obj = new test(10 , 20); obj.meth(obj); System.out.println(obj.a + " " + obj.b); } } |
A. | 10 20 |
B. | 20 10 |
C. | 20 40 |
D. | 40 20 |
Answer» C. 20 40 | |
533. |
What will be the output of the program? public abstract class AbstractTest { public int getNum() { return 45; } public abstract class Bar { public int getNum() { return 38; } } public static void main (String [] args) { AbstractTest t = new AbstractTest() { public int getNum() { return 22; } }; AbstractTest.Bar f = t.new Bar() { public int getNum() { return 57; } }; System.out.println(f.getNum() + " " + t.getNum()); } } |
A. | 57 22 |
B. | 45 38 |
C. | 45 57 |
D. | An exception occurs at runtime. |
Answer» B. 45 38 | |
534. |
When is the Float object, created in line 3, eligible for garbage collection? public Object m() { Object o = new Float(3.14F); Object [] oa = new Object[l]; oa[0] = o; /* Line 5 */ o = null; /* Line 6 */ oa[0] = null; /* Line 7 */ return o; /* Line 8 */ } |
A. | Just after line 5 |
B. | Just after line 6 |
C. | Just after line 7 |
D. | Just after line 8 |
Answer» D. Just after line 8 | |
535. |
When is the B object, created in line 3, eligible for garbage collection? void start() { A a = new A(); B b = new B(); a.s(b); b = null; /* Line 5 */ a = null; /* Line 6 */ System.out.println("start completed"); /* Line 7 */ } |
A. | After line 5 |
B. | After line 6 |
C. | After line 7 |
D. | There is no way to be absolutely certain. |
Answer» E. | |
536. |
Where will be the most chance of the garbage collector being invoked? class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); /* Line 6 */ } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } |
A. | After line 9 |
B. | After line 10 |
C. | After line 11 |
D. | Garbage collector never invoked in methodA() |
Answer» E. | |
537. |
At what point is the Bar object, created on line 6, eligible for garbage collection? class Bar { } class Test { Bar doBar() { Bar b = new Bar(); /* Line 6 */ return b; /* Line 7 */ } public static void main (String args[]) { Test t = new Test(); /* Line 11 */ Bar newBar = t.doBar(); /* Line 12 */ System.out.println("newBar"); newBar = new Bar(); /* Line 14 */ System.out.println("finishing"); /* Line 15 */ } } |
A. | After line 12 |
B. | After line 14 |
C. | After line 7, when doBar() completes |
D. | After line 15, when main() completes |
Answer» C. After line 7, when doBar() completes | |
538. |
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"); Method methods[] = c.getMethods(); for (int i = 0; i < methods.length; i++) System.out.println(methods[i]); } catch (Exception e) { System.out.print("Exception"); } } } |
A. | 10 |
B. | Box #0 [10]. |
C. | Box contains [10]. |
D. | Box #0 contains [10]. |
Answer» E. | |
539. |
What is the length of the application box made by this program? import java.awt.*; import java.applet.*; public class myapplet extends Applet { Graphic g; g.drawString("A Simple Applet",20,20); } |
A. | 20 |
B. | Default value |
C. | Compilation Error |
D. | Runtime Error |
Answer» D. Runtime Error | |
540. |
When is the Demo object eligible for garbage collection? class Test { private Demo d; void start() { d = new Demo(); this.takeDemo(d); /* Line 7 */ } /* Line 8 */ void takeDemo(Demo demo) { demo = null; demo = new Demo(); } } |
A. | After line 7 |
B. | After line 8 |
C. | After the start() method completes |
D. | When the instance running this code is made eligible for garbage collection. |
Answer» E. | |
541. |
After line 8 runs. how many objects are eligible for garbage collection? public class X { public static void main(String [] args) { X x = new X(); X x2 = m1(x); /* Line 6 */ X x4 = new X(); x2 = x4; /* Line 8 */ doComplexStuff(); } static X m1(X mx) { mx = new X(); return mx; } } |
A. | 0 |
B. | 1 |
C. | 2 |
D. | 3 |
Answer» C. 2 | |
542. |
What will be the output of the program? Note: The command line invocation: > java Test red green blue public class Test { public static void main (String[] args) { String foo = args[1]; String bar = args[2]; String baz = args[3]; System.out.println("baz = " + baz); /* Line 8 */ } } |
A. | Baz = |
B. | Baz = null |
C. | Baz = blue |
D. | Runtime Exception |
Answer» E. | |
543. |
What will be the output of the program? public static void main(String[] args) { Object obj = new Object() { public int hashCode() { return 42; } }; System.out.println(obj.hashCode()); } |
A. | 42 |
B. | Runtime Exception |
C. | Compile Error at line 2 |
D. | Compile Error at line 5 |
Answer» B. Runtime Exception | |
544. |
What will be the output of the program? public class Test { public static void main (String args[]) { String str = NULL; System.out.println(str); } } |
A. | NULL |
B. | Compile Error |
C. | Code runs but no output |
D. | Runtime Exception |
Answer» C. Code runs but no output | |
545. |
What will be the output of the program? package foo; import java.util.Vector; /* Line 2 */ private class MyVector extends Vector { int i = 1; /* Line 5 */ public MyVector() { i = 2; } } public class MyNewVector extends MyVector { public MyNewVector () { i = 4; /* Line 15 */ } public static void main (String args []) { MyVector v = new MyNewVector(); /* Line 19 */ } } |
A. | Compilation will succeed. |
B. | Compilation will fail at line 3. |
C. | Compilation will fail at line 5. |
D. | Compilation will fail at line 15. |
Answer» C. Compilation will fail at line 5. | |
546. |
What will be the output of the program? public class Test { private static int[] x; public static void main(String[] args) { System.out.println(x[0]); } } |
A. | 0 |
B. | Null |
C. | Compile Error |
D. | NullPointerException at runtime |
Answer» E. | |
547. |
What will be the output of the program? import java.util.*; class I { public static void main (String[] args) { Object i = new ArrayList().iterator(); System.out.print((i instanceof List)+","); System.out.print((i instanceof Iterator)+","); System.out.print(i instanceof ListIterator); } } |
A. | Prints: false, false, false |
B. | Prints: false, false, true |
C. | Prints: false, true, false |
D. | Prints: false, true, true |
Answer» D. Prints: false, true, true | |
548. |
Assuming that the equals() and hashCode() methods are properly implemented, if the output is x = 1111 , which of the following statements will always be true? x = 0; if (x1.hashCode() != x2.hashCode() ) x = x + 1; if (x3.equals(x4) ) x = x + 10; if (!x5.equals(x6) ) x = x + 100; if (x7.hashCode() == x8.hashCode() ) x = x + 1000; System.out.println("x = " + x); |
A. | X2.equals(x1) |
B. | X3.hashCode() == x4.hashCode() |
C. | X5.hashCode() != x6.hashCode() |
D. | X8.equals(x7) |
Answer» C. X5.hashCode() != x6.hashCode() | |
549. |
Which of the following are true statements? 1. The Iterator interface declares only three methods: hasNext, next and remove. 2. The ListIterator interface extends both the List and Iterator interfaces. 3. The ListIterator interface provides forward and backward iteration capabilities. 4. The ListIterator interface provides the ability to modify the List during iteration. 5.The ListIterator interface provides the ability to determine its position in the List. |
A. | 2, 3, 4 and 5 |
B. | 1, 3, 4 and 5 |
C. | 3, 4 and 5 |
D. | 1, 2 and 3 |
Answer» C. 3, 4 and 5 | |
550. |
What will be the output of the program? interface Count { short counter = 0; void countUp(); } public class TestCount implements Count { public static void main(String [] args) { TestCount t = new TestCount(); t.countUp(); } public void countUp() { for (int x = 6; x>counter; x--, ++counter) /* Line 14 */ { System.out.print(" " + counter); } } } |
A. | 0 1 2 |
B. | 1 2 3 |
C. | 0 1 2 3 |
D. | Compilation fails |
Answer» E. | |