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.

601.

What is the output of this program? import java.util.*; public class genericstack { Stack stk = new Stack (); public void push(E obj) { stk.push(obj); } public E pop() { E obj = stk.pop(); return obj; } } class Output { public static void main(String args[]) { genericstack gs = new genericstack(); gs.push(36); System.out.println(gs.pop()); } }

A. 0
B. 36
C. Runtime Error
D. Compilation Error
Answer» C. Runtime Error
602.

What is the output of this program? public class BoxDemo { public static void addBox(U u, java.util.List> boxes) { Box box = new Box<>(); box.set(u); boxes.add(box); } public static void outputBoxes(java.util.List> boxes) { int counter = 0; for (Box box: boxes) { U boxContents = box.get(); System.out.println("Box #" + counter + " contains [" + boxContents.toString() + "]"); counter++; } } public static void main(String[] args) { java.util.ArrayList> listOfIntegerBoxes = new java.util.ArrayList<>(); BoxDemo.addBox(Integer.valueOf(10), listOfIntegerBoxes); BoxDemo.outputBoxes(listOfIntegerBoxes); } }

A. 10
B. Box #0 [10].
C. Box contains [10].
D. Box #0 contains [10].
Answer» E.
603.

What is the output of this program? import java.util.*; public class genericstack { Stack stk = new Stack (); public void push(E obj) { stk.push(obj); } public E pop() { E obj = stk.pop(); return obj; } } class Output { public static void main(String args[]) { genericstack gs = new genericstack(); gs.push("Hello"); System.out.print(gs.pop() + " "); genericstack gs = new genericstack(); gs.push(36); System.out.println(gs.pop()); } }

A. Error
B. Hello
C. 36
D. Hello 36
Answer» E.
604.

Which of the following is good coding practice to determine oddity? i) public boolen abc(int num) { return num % 2 == 1; } ii) public boolean xyz(int num) { return (num & 1)!= 0; }

A. I
B. Ii
C. Option (i) causes compilation error
D. Option (ii) causes compilation error
Answer» C. Option (i) causes compilation error
605.

What one of the following is best practice to handle Null Pointer exception? i) int noOfStudents = line.listStudents().count; ii) int noOfStudents = getCountOfStudents(line); public int getCountOfStudents(List line) { if(line != null) { if(line.listOfStudents() != null) { return line.listOfStudents().size(); } } throw new NullPointerException("List is empty"); }

A. Option (i)
B. Option (ii)
C. Compilation Error
D. Option (ii) gives incorrect result
Answer» C. Compilation Error
606.

What is the output of this program? class evaluate { public static void main(String args[]) { int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); } }

A. 38
B. 39
C. 40
D. 41
Answer» D. 41
607.

What is the output of this program? class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i/2; array_variable[i]++; System.out.print(array_variable[i] + " "); i++; } } }

A. 0 2 4 6 8
B. 1 2 3 4 5
C. 0 1 2 3 4 5 6 7 8 9
D. 1 2 3 4 5 6 7 8 9 10
Answer» C. 0 1 2 3 4 5 6 7 8 9
608.

What is the prototype of the default constructor of this class? public class prototype { }

A. Prototype( )
B. Prototype(void)
C. Public prototype(void)
D. Public prototype( )
Answer» E.
609.

What is the error in this code? byte b = 50; b = b * 50;

A. B cannot contain value 100, limited by its range
B. * operator has converted b * 50 into int, which can not be converted to byte without casting
C. B cannot contain value 50
D. No error in this code
Answer» C. B cannot contain value 50
610.

What is the output of this program? class char_increment { public static void main(String args[]) { char c1 = 'D'; char c2 = 84; c2++; c1++; System.out.println(c1 + " " + c2); } }

A. E U
B. U E
C. V E
D. U F
Answer» B. U E
611.

What is the output of this program? class conversion { public static void main(String args[]) { double a = 295.04; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); } }

A. 38 43
B. 39 44
C. 295 300
D. 295.04 300
Answer» C. 295 300
612.

Which of these class is used to encapsulate IP address and DNS?

A. DatagramPacket
B. URL
C. InetAddress
D. ContentHandler
Answer» D. ContentHandler
613.

What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("mcqsmentor.com"); InetAddress obj2 = InetAddress.getByName("mcqsmentor.com"); boolean x = obj1.equals(obj2); System.out.print(x); } }

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

What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws UnknownHostException { InetAddress obj1 = InetAddress.getByName("cisco.com"); InetAddress obj2 = InetAddress.getByName("mcqsmentor.com"); boolean x = obj1.equals(obj2); System.out.print(x); } }

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

What is the output of this program? import java.net.*; class networking { public static void main(String[] args) throws MalformedURLException { URL obj = new URL("https://www.mcqsmentor.com/"); System.out.print(obj.toExternalForm()); } }

A. mcqsmentor
B. mcqsmentor.com
C. www.mcqsmentor.com
D. https://www.mcqsmentor.com/
Answer» E.
616.

What is the output of this program? import java.io.*; class streams { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeInt(5); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { int z; FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); z = ois.readInt(); ois.close(); System.out.println(x); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } }

A. 5
B. Void
C. Serialization
D. Deserialization
Answer» B. Void
617.

What is the output of this program? import java.io.*; class serialization { public static void main(String[] args) { try { Myclass object1 = new Myclass("Hello", -7, 2.1e10); FileOutputStream fos = new FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object1); oos.flush(); oos.close(); } catch(Exception e) { System.out.println("Serialization" + e); System.exit(0); } try { int x; FileInputStream fis = new FileInputStream("serial"); ObjectInputStream ois = new ObjectInputStream(fis); x = ois.readInt(); ois.close(); System.out.println(x); } catch (Exception e) { System.out.print("deserialization"); System.exit(0); } } } class Myclass implements Serializable { String s; int i; double d; Myclass(String s, int i, double d) { this.d = d; this.i = i; this.s = s; } }

A. -7
B. Hello
C. 2.1E10
D. Deserialization
Answer» E.
618.

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 = input1.read()) != -1) { System.out.print((char)i); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. Abc
B. Abcd
C. Abcde
D. Abcdef
Answer» E.
619.

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) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. Abc
B. Abcd
C. Abcde
D. Abcdef
Answer» B. Abcd
620.

What is the output of this program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; 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, 1, 4); int i; int j; try { while ((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

A. Abc
B. Abcd
C. Abcde
D. None of the mentioned
Answer» E.
621.

Which of these methods of Character wrapper can be used to obtain the char value contained in Character object.

A. Get()
B. GetVhar()
C. CharValue()
D. GetCharacter()
Answer» D. GetCharacter()
622.

What is the output of this program? class Output { public static void main(String args[]) { int a = Character.MAX_VALUE; System.out.print((char)a); } }

A. <
B. >
C. ?
D. $
Answer» D. $
623.

What is the output of this program? class Output { public static void main(String args[]) { int a = Character.MIN_VALUE; System.out.print((char)a); } }

A. <
B. !
C.
D. @Space
Answer» E.
624.

What is the output of this program? class Output { public static void main(String args[]) { String str = "true"; boolean x = Boolean.valueOf(str); System.out.print(x); } }

A. True
B. False
C. Compilation Error
D. Runtime Error
Answer» B. False
625.

What is the output of this program? class Output { public static void main(String args[]) { String str = "true false true"; boolean x = Boolean.valueOf(str); System.out.print(x); } }

A. True
B. False
C. Compilation Error
D. Runtime Error
Answer» C. Compilation Error
626.

What is the output of this program? class exception_handling { public static void main(String args[]) { try { int a[] = {1, 2,3 , 4, 5}; for (int i = 0; i < 7; ++i) System.out.print(a[i]); } catch(ArrayIndexOutOfBoundsException e) { System.out.print("0"); } } }

A. 12345
B. 12345A
C. 12345B
D. Compilation Error
Answer» D. Compilation Error
627.

What is the output of this program? class A { int x; int y; void display() { System.out.print(x + " " + y); } } class Output { public static void main(String args[]) { A obj1 = new A(); A obj2 = new A(); obj1.x = 1; obj1.y = 2; obj2 = obj1.clone(); obj1.display(); obj2.display(); } }

A. 1 2 0 0
B. 1 2 1 2
C. 0 0 0 0
D. System Dependent
Answer» C. 0 0 0 0
628.

What is the output of this program? class Output { public static void main(String args[]) { double 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
629.

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

A. 0
B. 1.7976931348623157E308
C. 1.7976931348623157E30
D. None of the mentioned
Answer» C. 1.7976931348623157E30
630.

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

A. 0
B. 4.9E-324
C. 1.7976931348623157E308
D. None of the mentioned
Answer» C. 1.7976931348623157E308
631.

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

A. 0
B. 257.0
C. 257.57812
D. 257.578123456789
Answer» D. 257.578123456789
632.

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

A. 0
B. 3
C. 3.0
D. 4
Answer» C. 3.0
633.

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

What is the output of this program? class Output { public static void main(String args[]) { char a = (char) 98; a = Character.toUpperCase(a); System.out.print(a); } }

A. b
B. c
C. B
D. C
Answer» D. C
635.

What is the output of this program? class Output { public static void main(String args[]) { char a = '@'; boolean x = Character.isLetter(a); System.out.print(x); } }

A. True
B. False
C.
D. @B
Answer» C.
636.

What is the output of this program? class Output { public static void main(String args[]) { String str = "true false"; boolean x = Boolean.parseBoolean(str); System.out.print(x); } }

A. True
B. False
C. System Dependent
D. Compilation Error
Answer» C. System Dependent
637.

What is the output of this program? class Output { public static void main(String args[]) { String x = Boolean.toString(false); } }

A. True
B. False
C. System Dependent
D. Compilation Error
Answer» C. System Dependent
638.

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

A. 0
B. 1
C. 2
D. 3
Answer» D. 3
639.

Will this program generate same output is executed again? class Output { public static void main(String args[]) { int y = double z = Math.random(); System.out.print(y); } }

A. Yes
B. No
C. Compiler Dependent
D. Operating System Dependent
Answer» C. Compiler Dependent
640.

What is the value of d after this line of code has been executed? double d = Math.round ( 2.5 + Math.random() );

A. 2
B. 3
C. 4
D. 2.5
Answer» C. 4
641.

What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

A. My Thread
B. Thread[My Thread,5,main].
C. Compilation Error
D. Runtime Error
Answer» D. Runtime Error
642.

What is the output of this program? class newthread implements Runnable { Thread t; newthread() { t = new Thread(this,"My Thread"); t.start(); } public void run() { System.out.println(t); } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }

A. My Thread
B. Thread[My Thread,5,main].
C. Compilation Error
D. Runtime Error
Answer» B. Thread[My Thread,5,main].
643.

Which of the following are valid calls to Math.max? 1. Math.max(1,4) 2. Math.max(2.3, 5) 3. Math.max(1, 3, 5, 7) 4. Math.max(-1.5, -2.8f)

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

Select how you would start the program to cause it to print: Arg is 2 public class Myfile { public static void main (String[] args) { String biz = args[1]; String baz = args[2]; String rip = args[3]; System.out.println("Arg is " + rip); } }

A. Java Myfile 222
B. Java Myfile 1 2 2 3 4
C. Java Myfile 1 3 2 2
D. Java Myfile 0 1 2 3
Answer» D. Java Myfile 0 1 2 3
645.

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

A. 0
B. 1
C. 257
D. 257.0
Answer» E.
646.

What is the output of this program? class Output { public static void main(String args[]) { Long i = new Long(256); System.out.print(i.hashCode()); } }

A. 256
B. 256.0
C. 256.00
D. 257.00
Answer» B. 256.0
647.

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, 2, b, 1, a.length-2); System.out.print(new String(a) + " " + new String(b)); } }

A. ABCDEF GHIJKL
B. ABCDEF GCDEFL
C. GHIJKL ABCDEF
D. GCDEFL GHIJKL
Answer» C. GHIJKL ABCDEF
648.

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, 1, b, 3, 0); System.out.print(new String(a) + " " + new String(b)); } }

A. ABCDEF GHIJKL
B. ABCDEF GCDEFL
C. GHIJKL ABCDEF
D. GCDEFL GHIJKL
Answer» B. ABCDEF GCDEFL
649.

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, 3, a.length - 3); System.out.print(new String(a) + " " + new String(b)); } }

A. ABCDEF ABCDEF
B. ABCDEF GHIJKL
C. ABCDEF GHIABC
D. GHIJKL GHIJKL
Answer» D. GHIJKL GHIJKL
650.

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, 2, b, 3, a.length - 4); System.out.print(new String(a) + " " + new String(b)); } }

A. ABCDEF ABCDEF
B. ABCDEF GHIJKL
C. ABCDEF GHIABC
D. ABCDEF GHICDL
Answer» E.