

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.
301. |
What is the output of this program?
import java.util.*; class LOCALE_CLASS { public static void main(String args[]) { Locale obj = new Locale("PAKISTAN") ; System.out.print(obj.getCountry()); } } |
A. | Pakistan |
B. | PAKISTAN |
C. | Compilation Error |
D. | Nothing is displayed |
Answer» E. | |
302. |
What is the output of this program?
import java.util.*; class LOCALE_CLASS { public static void main(String args[]) { Locale obj = new Locale("URDU", "PAKISTAN") ; System.out.print(obj.getCountry()); } } |
A. | Pakistan |
B. | PAKISTAN |
C. | Compilation Error |
D. | Nothing is displayed |
Answer» C. Compilation Error | |
303. |
What is the output of this program?
import java.util.*; class hashtable { public static void main(String args[]) { Hashtable obj = new Hashtable(); obj.put("A", new Integer(3)); obj.put("B", new Integer(2)); obj.put("C", new Integer(8)); obj.remove(new String("A")); System.out.print(obj); } } |
A. | {C=8, B=2} |
B. | [C=8, B=2]. |
C. | {A=3, C=8, B=2} |
D. | [A=3, C=8, B=2]. |
Answer» B. [C=8, B=2]. | |
304. |
What is the output of this program?
import java.util.*; class hashtable { public static void main(String args[]) { Hashtable obj = new Hashtable(); obj.put("A", new Integer(3)); obj.put("B", new Integer(2)); obj.put("C", new Integer(8)); System.out.print(obj.toString()); } } |
A. | {AB, BC, CD} |
B. | [AB, BC, CD]. |
C. | [3, 2, 8]. |
D. | {3, 2, 8} |
Answer» C. [3, 2, 8]. | |
305. |
What is the output of this program?
import java.util.*; class Bitset { public static void main(String args[]) { BitSet obj = new BitSet(5); for (int i = 0; i < 5; ++i) obj.set(i); System.out.print(obj.get(3)); } } |
A. | 2 |
B. | 3 |
C. | 4 |
D. | 5 |
Answer» B. 3 | |
306. |
What is the output of this program?
import java.util.*; class date { public static void main(String args[]) { Date obj = new Date(); System.out.print(obj); } } |
A. | Prints Present Date |
B. | Runtime Error |
C. | Any Garbage Value |
D. | Prints Present Time & Date |
Answer» E. | |
307. |
What is the output of this program?
import java.util.*; class Bitset { public static void main(String args[]) { BitSet obj1 = new BitSet(5); BitSet obj2 = new BitSet(10); for (int i = 0; i < 5; ++i) obj1.set(i); for (int i = 3; i < 13; ++i) obj2.set(i); obj1.and(obj2); System.out.print(obj1); } } |
A. | {0, 1} |
B. | {2, 4} |
C. | {3, 4} |
D. | {3, 4, 5} |
Answer» D. {3, 4, 5} | |
308. |
What is the output of this program?
import java.util.*; class Collection_Algos { public static void main(String args[]) { LinkedList list = new LinkedList(); list.add(new Integer(2)); list.add(new Integer(8)); list.add(new Integer(5)); list.add(new Integer(1)); Iterator i = list.iterator(); while(i.hasNext()) System.out.print(i.next() + " "); } } |
A. | 2 8 5 1 |
B. | 1 5 8 2 |
C. | 2 |
D. | 2 1 8 5 |
Answer» C. 2 | |
309. |
Which of these will create and start this thread?
public class MyRunnable implements Runnable { public void run() { // some code here } } |
A. | New Runnable(MyRunnable).start(); |
B. | New Thread(MyRunnable).run(); |
C. | New Thread(new MyRunnable()).start(); |
D. | New MyRunnable().start(); |
Answer» D. New MyRunnable().start(); | |
310. |
What is the output of this program?
class bitwise_operator { public static void main(String args[]) { int var1 = 42; int var2 = ~var1; System.out.print(var1 + " " + var2); } } |
A. | 42 42 |
B. | 43 43 |
C. | 42 -43 |
D. | 42 43 |
Answer» D. 42 43 | |
311. |
What is the output of this program?
class bitwise_operator { public static void main(String args[]) { int a = 3; int b = 6; int c = a | b; int d = a & b; System.out.println(c + " " + d); } } |
A. | 7 2 |
B. | 7 7 |
C. | 7 5 |
D. | 5 2 |
Answer» B. 7 7 | |
312. |
Which of the following operators can operate on a boolean variable?1. && |
A. | 3 & 2 |
B. | 1 & 4 |
C. | 1, 2 & 4 |
D. | 1, 2 & 3 |
Answer» E. | |
313. |
What will be the output of the program?
int x = 3; int y = 1; if (x = y) /* Line 3 */ { System.out.println("x =" + x); } |
A. | X = 1 |
B. | X = 3 |
C. | Compilation fails. |
D. | The code runs with no output. |
Answer» D. The code runs with no output. | |
314. |
What will be the output of the program?
Float f = new Float("12"); switch (f) { case 12: System.out.println("Twelve"); case 0: System.out.println("Zero"); default: System.out.println("Default"); } |
A. | Zero |
B. | Twelve |
C. | Default |
D. | Compilation fails |
Answer» E. | |
315. |
What will be the output of the program?
int i = 0; while(1) { if(i == 4) { break; } ++i; } System.out.println("i = " + i); |
A. | I = 0 |
B. | I = 3 |
C. | I = 4 |
D. | Compilation fails. |
Answer» E. | |
316. |
What will be the output of the program?
public class Delta { static boolean foo(char c) { System.out.print(c); return true; } public static void main( String[] argv ) { int i = 0; for (foo('A'); foo('B') && (i < 2); foo('C')) { i++; foo('D'); } } } |
A. | ABDCBDCB |
B. | ABCDABCD |
C. | Compilation fails. |
D. | An exception is thrown at runtime. |
Answer» B. ABCDABCD | |
317. |
Which two statements are equivalent?1. 16*4 |
A. | 1 and 2 |
B. | 2 and 4 |
C. | 3 and 4 |
D. | 1 and 3 |
Answer» C. 3 and 4 | |
318. |
Which two statements are equivalent?1. 3/2 2. 3<2 3. 3*4 4. 3<<2 |
A. | 1 and 2 |
B. | 2 and 3 |
C. | 3 and 4 |
D. | 1 and 4 |
Answer» D. 1 and 4 | |
319. |
Which three statements are true?1. f1 == f2
|
A. | 1, 2 and 3 |
B. | 2, 4 and 5 |
C. | 3, 4 and 5 |
D. | 1, 4 and 5 |
Answer» C. 3, 4 and 5 | |
320. |
Which two are equal?1. 32/4 3. 2^5 4. 128 >>> 2 |
A. | 1 and 2 |
B. | 2 and 4 |
C. | 1 and 3 |
D. | 2 and 3 |
Answer» C. 1 and 3 | |
321. |
Determine the output of following code.
public void foo( boolean a, boolean b) { if( a ) { System.out.println("A"); /* Line 5 */ } else if(a && b) /* Line 7 */ { System.out.println( "A && B"); } else /* Line 11 */ { if ( !b ) { System.out.println( "notB") ; } else { System.out.println( "ELSE" ) ; } } } |
A. | If a is true and b is true then the output is "A && B" |
B. | If a is true and b is false then the output is "notB" |
C. | If a is false and b is true then the output is "ELSE" |
D. | If a is false and b is false then the output is "ELSE" |
Answer» D. If a is false and b is false then the output is "ELSE" | |
322. |
Which two are acceptable types for x?1. byte
|
A. | 1 and 3 |
B. | 2 and 4 |
C. | 3 and 5 |
D. | 4 and 6 |
Answer» B. 2 and 4 | |
323. |
Which statement is true?
public void test(int x) { int odd = 1; if(odd) /* Line 4 */ { System.out.println("odd"); } else { System.out.println("even"); } } |
A. | Compilation fails. |
B. | "odd" will always be output. |
C. | "even" will always be output. |
D. | "odd" will be output for odd values of x, and "even" for even values. |
Answer» B. "odd" will always be output. | |
324. |
Which statement is true?
public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } } |
A. | There is a syntax error on line 1. |
B. | There are syntax errors on lines 1 and 6. |
C. | There are syntax errors on lines 1, 6, and 8. |
D. | There is a syntax error on line 6. |
Answer» E. | |
325. |
What will be the output of the program?
int I = 0; label: if (I < 2) { System.out.print("I is " + I); I++; continue label; } |
A. | I is 0 |
B. | I is 0 I is 1 |
C. | Compilation fails. |
D. | None of the above |
Answer» D. None of the above | |
326. |
What will be the output of the program?
int i = l, j = -1; switch (i) { case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; } System.out.println("j = " + j); |
A. | J = -1 |
B. | J = 0 |
C. | J = 1 |
D. | Compilation fails. |
Answer» E. | |
327. |
What will be the output of the program?
int i = 1, j = 10; do { if(i > j) { break; } j--; } while (++i < 5); System.out.println("i = " + i + " and j = " + j); |
A. | I = 6 and j = 5 |
B. | I = 5 and j = 5 |
C. | I = 6 and j = 4 |
D. | I = 5 and j = 6 |
Answer» E. | |
328. |
What will be the output of the program?
public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 3; z++) { switch (z) { case x: System.out.print("0 "); case x-1: System.out.print("1 "); case x-2: System.out.print("2 "); } } } } |
A. | 0 1 2 |
B. | 0 1 2 1 2 2 |
C. | 2 1 0 1 0 0 |
D. | 2 1 2 0 1 2 |
Answer» E. | |
329. |
What will be the output of the program?
public class SwitchTest { public static void main(String[] args) { System.out.println("value =" + switchIt(4)); } public static int switchIt(int x) { int j = 1; switch (x) { case l: j++; case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++; } return j + x; } } |
A. | Value = 2 |
B. | Value = 4 |
C. | Value = 6 |
D. | Value = 8 |
Answer» E. | |
330. |
What will be the output of the program?
public class If2 { static boolean b1, b2; public static void main(String [] args) { int x = 0; if ( !b1 ) /* Line 7 */ { if ( !b2 ) /* Line 9 */ { b1 = true; x++; if ( 5 > 6 ) { x++; } if ( !b1 ) x = x + 10; else if ( b2 = true ) /* Line 19 */ x = x + 100; else if ( b1 | b2 ) /* Line 21 */ x = x + 1000; } } System.out.println(x); } } |
A. | 0 |
B. | 1 |
C. | 101 |
D. | 111 |
Answer» D. 111 | |
331. |
What will be the output of the program?
for (int i = 0; i < 4; i += 2) { System.out.print(i + " "); } System.out.println(i); /* Line 5 */ |
A. | 0 2 4 |
B. | 0 2 4 5 |
C. | 0 1 2 3 4 |
D. | Compilation fails. |
Answer» E. | |
332. |
What will be the output of the program?
public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 3; z++) { switch (z) { case y: System.out.print("0 "); /* Line 11 */ case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ } } } } |
A. | 0 1 2 |
B. | 0 1 2 1 2 2 |
C. | Compilation fails at line 11. |
D. | Compilation fails at line 12. |
Answer» D. Compilation fails at line 12. | |
333. |
What will be the output of the program?
public class If1 { static boolean b; public static void main(String [] args) { short hand = 42; if ( hand < 50 && !b ) /* Line 7 */ hand++; if ( hand > 50 ); /* Line 9 */ else if ( hand > 40 ) { hand += 7; hand++; } else --hand; System.out.println(hand); } } |
A. | 41 |
B. | 42 |
C. | 50 |
D. | 51 |
Answer» E. | |
334. |
What will be the output of the program?
public class Test { public static void main(String [] args) { int I = 1; do while ( I < 1 ) System.out.print("I is " + I); while ( I > 1 ) ; } } |
A. | I is 1 |
B. | I is 1 I is 1 |
C. | No output is produced. |
D. | Compilation error |
Answer» D. Compilation error | |
335. |
What will be the output of the program?
int x = l, y = 6; while (y--) { x++; } System.out.println("x = " + x +" y = " + y); |
A. | X = 6 y = 0 |
B. | X = 7 y = 0 |
C. | X = 6 y = -1 |
D. | Compilation fails. |
Answer» E. | |
336. |
What will be the output of the program?
int I = 0; outer: while (true) { I++; inner: for (int j = 0; j < 10; j++) { I += j; if (j == 3) continue inner; break outer; } continue outer; } System.out.println(I); |
A. | 1 |
B. | 2 |
C. | 3 |
D. | 4 |
Answer» B. 2 | |
337. |
What will be the output of the program?
for(int i = 0; i < 3; i++) { switch(i) { case 0: break; case 1: System.out.print("one "); case 2: System.out.print("two "); case 3: System.out.print("three "); } } System.out.println("done"); |
A. | Done |
B. | One two done |
C. | One two three done |
D. | One two three two three done |
Answer» E. | |
338. |
What will be the output of the program?
public class Test { public static void main(String args[]) { int i = 1, j = 0; switch(i) { case 2: j += 6; case 4: j += 1; default: j += 2; case 0: j += 4; } System.out.println("j = " + j); } } |
A. | J = 0 |
B. | J = 2 |
C. | J = 4 |
D. | J = 6 |
Answer» E. | |
339. |
What will be the output of the program?
boolean bool = true; if(bool = false) /* Line 2 */ { System.out.println("a"); } else if(bool) /* Line 6 */ { System.out.println("b"); } else if(!bool) /* Line 10 */ { System.out.println("c"); /* Line 12 */ } else { System.out.println("d"); } |
A. | a |
B. | b |
C. | c |
D. | d |
Answer» D. d | |
340. |
What will be the output of the program?
public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 4; z++) { switch (z) { case x: System.out.print("0 "); default: System.out.print("def "); case x-1: System.out.print("1 "); break; case x-2: System.out.print("2 "); } } } } |
A. | 0 def 1 |
B. | 2 1 0 def 1 |
C. | 2 1 0 def def |
D. | 2 1 0 def 1 def 1 |
Answer» E. | |
341. |
What will be the output of the program?
int i = 0, j = 5; tp: for (;;) { i++; for (;;) { if(i > --j) { break tp; } } System.out.println("i =" + i + ", j = " + j); |
A. | I = 1, j = 0 |
B. | I = 1, j = 4 |
C. | I = 3, j = 4 |
D. | Compilation fails. |
Answer» E. | |
342. |
What is the output of this program?
class Output { public static void main(String args[]) { int a = 1; int b = 2; int c; int d; c = ++b; d = a++; c++; b++; ++a; System.out.println(a + " " + b + " " + c); } } |
A. | 3 2 4 |
B. | 3 2 3 |
C. | 2 3 4 |
D. | 3 4 4 |
Answer» E. | |
343. |
What is the output of this program?
class leftshift_operator { public static void main(String args[]) { byte x = 64; int i; byte y; i = x << 2; y = (byte) (x << 2) System.out.print(i + " " + y); } } |
A. | 0 64 |
B. | 64 0 |
C. | 0 256 |
D. | 256 0 |
Answer» E. | |
344. |
What is the output of this program?
class rightshift_operator { public static void main(String args[]) { int x; x = 10; x = x >> 1; System.out.println(x); } } |
A. | 10 |
B. | 5 |
C. | 2 |
D. | 20 |
Answer» C. 2 | |
345. |
What is the output of this program?
class Output { public static void main(String args[]) { int a = 1; int b = 2; int c = 3; a |= 4; b >>= 1; c <<= 1; a ^= c; System.out.println(a + " " + b + " " + c); } } |
A. | 3 1 6 |
B. | 2 2 3 |
C. | 2 3 4 |
D. | 3 3 6 |
Answer» B. 2 2 3 | |
346. |
What is the output of this program?
class ternary_operator { public static void main(String args[]) { int x = 3; int y = ~ x; int z; z = x > y ? x : y; System.out.print(z); } } |
A. | 0 |
B. | 1 |
C. | 3 |
D. | -4 |
Answer» D. -4 | |
347. |
What is the output of this program?
class Output { public 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 owing to division by zero in if condition |
D. | Unpredictable behavior of program |
Answer» C. Runtime error owing to division by zero in if condition | |
348. |
What is the output of this program?
class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } |
A. | 0 |
B. | 1 |
C. | False |
D. | True |
Answer» D. True | |
349. |
What is the output of this program?
class Output { public static void main(String args[]) { int x=y=z=20; } } |
A. | Compile and runs fine |
B. | 20 |
C. | Run time error |
D. | Compile time error |
Answer» E. | |
350. |
What is the output of this program?
class Output { public static void main(String args[]) { int a,b,c,d; a=b=c=d=20 a+=b-=c*=d/=20 System.out.println(a+" "+b+" "+c+" "+d); } } |
A. | Compile time error |
B. | Runtime error |
C. | A=20 b=0 c=20 d=1 |
D. | None of the mentioned |
Answer» D. None of the mentioned | |