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.

351.

Which of these lines of code will give better performance?
 1. a | 4 + c >> b & 7; 2. (a | ((( 4 * c ) >> b ) & 7 )) 

A. 1 will give better performance as it has no parentheses
B. 2 will give better performance as it has parentheses
C. Both 1 & 2 will give equal performance
D. Dependent on the computer system
Answer» D. Dependent on the computer system
352.

What will be the output of the program?
 class Test { public static void main(String [] args) { int x=20; String sup = (x < 15) ? "small" : (x < 22)? "tiny" : "huge"; System.out.println(sup); } } 

A. Small
B. Tiny
C. Huge
D. Compilation fails
Answer» C. Huge
353.

What will be the output of the program?
 class Test { public static void main(String [] args) { int x= 0; int y= 0; for (int z = 0; z < 5; z++) { if (( ++x > 2 ) && (++y > 2)) { x++; } } System.out.println(x + " " + y); } } 

A. 5 2
B. 5 3
C. 6 3
D. 6 4
Answer» D. 6 4
354.

What is the output of this program?
 class operators { public static void main(String args[]) { int var1 = 5; int var2 = 6; int var3; var3 = ++ var2 * var1 / var2 + var2; System.out.print(var3); } } 

A. 10
B. 11
C. 12
D. 56
Answer» D. 56
355.

What is the output of this program?
 class operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } 

A. 24 8
B. 24 9
C. 27 8
D. 27 9
Answer» E.
356.

What will be the output of the program?
 class Test { public static void main(String [] args) { int x= 0; int y= 0; for (int z = 0; z < 5; z++) { if (( ++x > 2 ) || (++y > 2)) { x++; } } System.out.println(x + " " + y); } } 

A. 5 3
B. 8 2
C. 8 3
D. 8 5
Answer» C. 8 3
357.

What will be the output of the program?
 class Bitwise { public static void main(String [] args) { int x = 11 & 9; int y = x ^ 3; System.out.println( y | 12 ); } } 

A. 0
B. 7
C. 8
D. 14
Answer» E.
358.

What will be the output of the program?
 class SSBool { public static void main(String [] args) { boolean b1 = true; boolean b2 = false; boolean b3 = true; if ( b1 & b2 | b2 & b3 | b2 ) /* Line 8 */ System.out.print("ok "); if ( b1 & b2 | b2 & b3 | b2 | b1 ) /*Line 10*/ System.out.println("dokey"); } } 

A. Ok
B. Dokey
C. Ok dokey
D. No output is produced
Answer» C. Ok dokey
359.

What will be the output of the program?
 class PassA { public static void main(String [] args) { PassA p = new PassA(); p.start(); } void start() { long [] a1 = {3,4,5}; long [] a2 = fix(a1); System.out.print(a1[0] + a1[1] + a1[2] + " "); System.out.println(a2[0] + a2[1] + a2[2]); } long [] fix(long [] a3) { a3[1] = 7; return a3; } } 

A. 12 15
B. 15 15
C. 3 4 5 3 7 5
D. 3 7 5 3 7 5
Answer» C. 3 4 5 3 7 5
360.

What will be the output of the program?
 class Test { public static void main(String [] args) { Test p = new Test(); p.start(); } void start() { boolean b1 = false; boolean b2 = fix(b1); System.out.println(b1 + " " + b2); } boolean fix(boolean b1) { b1 = true; return b1; } } 

A. True true
B. False true
C. True false
D. False false
Answer» C. True false
361.

What will be the output of the program?
 class PassS { public static void main(String [] args) { PassS p = new PassS(); p.start(); } void start() { String s1 = "slip"; String s2 = fix(s1); System.out.println(s1 + " " + s2); } String fix(String s1) { s1 = s1 + "stream"; System.out.print(s1 + " "); return "stream"; } } 

A. Slip stream
B. Slipstream stream
C. Stream slip stream
D. Slipstream slip stream
Answer» E.
362.

What will be the output of the program?
 class BitShift { public static void main(String [] args) { int x = 0x80000000; System.out.print(x + " and "); x = x >>> 31; System.out.println(x); } } 

A. -2147483648 and 1
B. 0x80000000 and 0x00000001
C. -2147483648 and -1
D. 1 and -2147483648
Answer» B. 0x80000000 and 0x00000001
363.

What will be the output of the program?
 class Equals { public static void main(String [] args) { int x = 100; double y = 100.1; boolean b = (x = y); /* Line 7 */ System.out.println(b); } } 

A. True
B. False
C. Compilation fails
D. An exception is thrown at runtime
Answer» D. An exception is thrown at runtime
364.

What will be the output of the program?
 class SC2 { public static void main(String [] args) { SC2 s = new SC2(); s.start(); } void start() { int a = 3; int b = 4; System.out.print(" " + 7 + 2 + " "); System.out.print(a + b); System.out.print(" " + a + b + " "); System.out.print(foo() + a + b + " "); System.out.println(a + b + foo()); } String foo() { return "foo"; } } 

A. 9 7 7 foo 7 7foo
B. 72 34 34 foo34 34foo
C. 9 7 7 foo34 34foo
D. 72 7 34 foo34 7foo
Answer» E.
365.

What will be the output of the program?
 class Test { static int s; public static void main(String [] args) { Test p = new Test(); p.start(); System.out.println(s); } void start() { int x = 7; twice(x); System.out.print(x + " "); } void twice(int x) { x = x*2; s = x; } } 

A. 7 7
B. 7 14
C. 14 0
D. 14 14
Answer» C. 14 0
366.

What will be the output of the program?
 class Two { byte x; } class PassO { public static void main(String [] args) { PassO p = new PassO(); p.start(); } void start() { Two t = new Two(); System.out.print(t.x + " "); Two t2 = fix(t); System.out.println(t.x + " " + t2.x); } Two fix(Two tt) { tt.x = 42; return tt; } } 

A. Null null 42
B. 0 0 42
C. 0 42 42
D. 0 0 0
Answer» D. 0 0 0
367.

What will be the output of the program?
 class BoolArray { boolean [] b = new boolean[3]; int count = 0; void set(boolean [] x, int i) { x[i] = true; ++count; } public static void main(String [] args) { BoolArray ba = new BoolArray(); ba.set(ba.b, 0); ba.set(ba.b, 2); ba.test(); } void test() { if ( b[0] && b[1] | b[2] ) count++; if ( b[1] && b[(++count - 2)] ) count += 7; System.out.println("count = " + count); } } 

A. Count = 0
B. Count = 2
C. Count = 3
D. Count = 4
Answer» D. Count = 4
368.

What will be the output of the program?
 public class Test { public static void leftshift(int i, int j) { i <<= j; } public static void main(String args[]) { int i = 4, j = 2; leftshift(i, j); System.out.printIn(i); } } 

A. 2
B. 4
C. 8
D. 16
Answer» C. 8
369.

Which two of the following statements, inserted independently, could legally be inserted into missing section of this code?

1. boolean test = (Component instanceof t);
2. boolean test = (t instanceof Ticker);
3. boolean test = t.instanceof(Ticker);
4. boolean test = (t instanceof Component);

 import java.awt.*; class Ticker extends Component { public static void main (String [] args) { Ticker t = new Ticker(); /* Missing Statements ? */ } } 

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

Which of the following are legal lines of code?

1. int w = (int)888.8;
2. byte x = (byte)1000L;
3. long y = (byte)100;
4. byte z = (byte)100L;

A. 1 and 2
B. 2 and 3
C. 3 and 4
D. All statements are correct.
Answer» E.
371.

What is the output of this program?
 class comma_operator { public static void main(String args[]) { int sum = 0; for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1) sum += i; System.out.println(sum); } } 

A. 5
B. 6
C. 14
D. Compilation error
Answer» C. 14
372.

What is the output of this program?
 class selection_statements { public static void main(String args[]) { int var1 = 5; int var2 = 6; if ((var2 = 1) == var1) System.out.print(var2); else System.out.print(++var2); } } 

A. 1
B. 2
C. 3
D. 4
Answer» C. 3
373.

What would be the output of the following codesnippet if variable a=10?
 if(a<=0) { if(a==0) { System.out.println("1 "); } else { System.out.println("2 "); } } System.out.println("3 "); 

A. 1 2
B. 2 3
C. 1 3
D. 3
Answer» E.
374.

What is the output of this program?
 class Relational_operator { public static void main(String args[]) { int var1 = 5; int var2 = 6; System.out.print(var1 > var2); } } 

A. 1
B. 0
C. True
D. False
Answer» E.
375.

What is the output of this program?
 class bool_operator { public static void main(String args[]) { boolean a = true; boolean b = !true; boolean c = a | b; boolean d = a & b; boolean e = d ? b : c; System.out.println(d + " " + e); } } 

A. false false
B. frue ture
C. frue false
D. false true
Answer» E.
376.

What should be expression1 evaluate to in using ternary operator as in this line?

expression1 ? expression2 : expression3

A. Integer
B. Boolean
C. None of the mentioned
Answer» D.
377.

What is the value stored in x in following lines of code?

int x, y, z;
x = 0;
y = 1;
x = y = z = 8;

A. 0
B. 1
C. 9
D. 8
Answer» E.
378.

What is the order of precedence (highest to lowest) of following operators?

1. &
2. ^
3. ?:

A. 1 -&gt; 2 -&gt; 3
B. 2 -&gt; 1 -&gt; 3
C. 3 -&gt; 2 -&gt; 1
D. 2 -&gt; 3 -&gt; 1
Answer» B. 2 -&gt; 1 -&gt; 3
379.

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

Which three are valid declarations of a float?

1. float f1 = -343;
2. float f2 = 3.14;
3. float f3 = 0x12345;
4. float f4 = 42e7;
5. float f5 = 2001.0D;
6. float f6 = 2.81F;

A. 1, 2, 4
B. 2, 3, 5
C. 1, 3, 6
D. 2, 4, 6
Answer» D. 2, 4, 6
381.

Which three are legal array declarations?

1. int [] myScores [];
2. char [] myChars;
3. int [6] myScores;
4. Dog myDogs [];
5. Dog myDogs [7];

A. 1, 2, 4
B. 2, 4, 5
C. 2, 3, 4
D. All are correct.
Answer» B. 2, 4, 5
382.

Which three piece of codes are equivalent to line 3?

1. final int k = 4;
2. public int k = 4;
3. static int k = 4;
4. abstract int k = 4;
5. volatile int k = 4;
6. protected int k = 4;

 public interface Foo { int k = 4; /* Line 3 */ }  

A. 1, 2 and 3
B. 2, 3 and 4
C. 3, 4 and 5
D. 4, 5 and 6
Answer» B. 2, 3 and 4
383.

What will be the output of the program?

Note: The command-line invocation > java CommandArgsThree 1 2 3

 public class CommandArgsThree { public static void main(String [] args) { String [][] argCopy = new String[2][2]; int x; argCopy[0] = args; x = argCopy[0].length; for (int y = 0; y < x; y++) { System.out.print(" " + argCopy[0][y]); } } } 

A. 0 0
B. 1 2
C. 0 0 0
D. 1 2 3
Answer» E.
384.

What will be the output of the progra Note: The command-line invocation is

> java CommandArgs 1 2 3 4

 public class CommandArgs { public static void main(String [] args) { String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); } }  

A. Args[2] = 2
B. Args[2] = 3
C. Args[2] = null
D. An exception is thrown at runtime.
Answer» E.
385.

What will be the output of the program, if this code is executed with the command line:

> java F0091 world

 public class F0091 { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } }  

A. Hello
B. Hello Foo91
C. Hello world
D. The code does not run.
Answer» E.
386.

What will be the output of the program?
 public class TestDogs { public static void main(String [] args) { Dog [][] theDogs = new Dog[3][]; System.out.println(theDogs[2][0].toString()); } } class Dog { }  

A. Null
B. TheDogs
C. Compilation fails
D. An exception is thrown at runtime
Answer» E.
387.

What will be the output of the program ?
 public class Test { public static void main(String [] args) { signed int x = 10; for (int y=0; y<5; y++, x--) System.out.print(x + ", "); } }  

A. 10, 9, 8, 7, 6,
B. 9, 8, 7, 6, 5,
C. Compilation fails.
D. An exception is thrown at runtime.
Answer» D. An exception is thrown at runtime.
388.

What is the output of this program?
 class Output { public static void main(String args[]) { char a[] = {'a', '5', 'A', ' '}; System.out.print(Character.isDigit(a[0]) + " "); System.out.print(Character.isWhitespace(a[3]) + " "); System.out.print(Character.isUpperCase(a[2])); } } 

A. True false true
B. False true true
C. True true false
D. False false false
Answer» C. True true false
389.

What is the output of this program?
 class Output { public static void main(String args[]) { int x = 3.14; int y = (int) Math.abs(x); System.out.print(y); } } 

A. 0
B. 3
C. 3.0
D. 3.1
Answer» C. 3.0
390.

What is the output of this program?
 class Output { public static void main(String args[]) { double x = 3.1; double y = 4.5; double z = Math.max( x, y ); System.out.print(z); } } 

A. True
B. False
C. 3.1
D. 4.5
Answer» E.
391.

What is the output of this program?
 class Output { public static void main(String args[]) { double x = 2.0; double y = 3.0; double z = Math.pow( x, y ); System.out.print(z); } } 

A. 2.0
B. 4.0
C. 8.0
D. 9.0
Answer» D. 9.0
392.

What is the output of this program?
 42. What is the output of this program? import java.lang.System; class Output { public static void main(String args[]) { long start, end; start = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++); end = System.currentTimeMillis(); System.out.print(end - start); } } 

A. 0
B. 1
C. 1000
D. System Dependent
Answer» E.
393.

What is the output of this program?
 import java.lang.System; class Output { public static void main(String args[]) { byte a[] = { 65, 66, 67, 68, 69, 70 }; byte b[] = { 71, 72, 73, 74, 75, 76 }; System.arraycopy(a, 0, b, 0, a.length); System.out.print(new String(a) + " " + new String(b)); } } 

A. ABCDEF ABCDEF
B. ABCDEF GHIJKL
C. GHIJKL ABCDEF
D. GHIJKL GHIJKL
Answer» B. ABCDEF GHIJKL
394.

What is the output of this program?
 class Output { public static void main(String args[]) { Integer i = new Integer(257); byte x = i.byteValue(); System.out.print(x); } } 

A. 0
B. 1
C. 256
D. 257
Answer» C. 256
395.

What is the output of this program?
 class Output { public static void main(String args[]) { long start, end; start = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++); end = System.currentTimeMillis(); System.out.print(end - start); } } 

A. 0
B. 1
C. 1000
D. System Dependent
Answer» E.
396.

What is the output of this program?
 class Output { public static void main(String args[]) { byte a[] = { 65, 66, 67, 68, 69, 70 }; byte b[] = { 71, 72, 73, 74, 75, 76 }; System.arraycopy(a , 0, b, 0, a.length); System.out.print(new String(a) + " " + new String(b)); } } 

A. ABCDEF ABCDEF
B. ABCDEF GHIJKL
C. GHIJKL ABCDEF
D. GHIJKL GHIJKL
Answer» B. ABCDEF GHIJKL
397.

What is the output of this program?
 class output { public static void main(String args[]) { StringBuffer c = new StringBuffer("Hello"); StringBuffer c1 = new StringBuffer(" World"); c.append(c1); System.out.println(c); } } 

A. Hello
B. World
C. Helloworld
D. Hello World
Answer» E.
398.

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

What is the output of this program?
 import java.io.*; public class filesinputoutput { public static void main(String[] args) { String obj = "abc"; byte b[] = obj.getBytes(); ByteArrayInputStream obj1 = new ByteArrayInputStream(b); for (int i = 0; i < 2; ++ i) { int c; while((c = obj1.read()) != -1) { if(i == 0) { System.out.print(Character.toUpperCase((char)c)); obj2.write(1); } } System.out.print(obj2); } } } 

A. AaBaCa
B. ABCaaa
C. AaaBaaCaa
D. AaBaaCaaa
Answer» E.
400.

What is the Message is displayed in the applet 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. A Simple Applet
B. A Simple Applet 20 20
C. Compilation Error
D. Runtime Error
Answer» B. A Simple Applet 20 20