Java Multiple Choice Question MCQ
Categories: Java
1. Which exception is thrown when java is out of memory? a) MemoryError b) OutOfMemoryError c) MemoryOutOfBoundsException d) MemoryFullException Answer: b 2. What will be the output of the following Java code? class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } } a) abc b) a c) b d) c Answer: a 3. Which of these are selection statements in Java? a) break b) continue c) for() d) if() Answer: d 4. What will be the output of the following Java 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) 1 b) 120 c) 0 d) None of the mentioned Answer: a 5. What will be the output of the following Java code? class output { public static void main(String args[]) { String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var); } } a) 0 b) true c) 1 d) false Answer: d 6. Which of these keywords is used to define interfaces in Java? a) intf b) Intf c) interface d) Interface Answer: c 7. What will be the output of the following Java program? class output { public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Quiz"); StringBuffer s2 = s1.reverse(); System.out.println(s2); } } a) QuizziuQ b) ziuQQuiz c) Quiz d) ziuQ Answer: d 8. What will be the output of the following Java code? class Output { public static void main(String args[]) { Integer i = new Integer(257); byte x = i.byteValue(); System.out.print(x); } } a) 257 b) 256 c) 1 d) 0 Answer: c 9. What will be the output of the following Java 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) 9.0 b) 8.0 c) 4.0 d) 2.0 Answer: b 10. Which of the following is a superclass of every class in Java? a) ArrayList b) Abstract class c) Object class d) String Answer: c