Java Programming - MCQ Practice Questions
Practice free Java Programming multiple-choice questions with detailed answers and explanations. Perfect for competitive exam preparation.
958 questions | 100% Free
Consider the code: int a = 5; int b = a++; System.out.println(a + " " + b); What is the output?
What will be printed? System.out.println(10 + 20 + "Java");
What is the scope of a local variable in Java?
Consider: int x = 0; System.out.println(x == 0 && x != 1); What is the output?
What is the result of: int x = 5; System.out.println(x++ + ++x);?
Which statement about Java's garbage collection is true?
What will be the output? class Test { public static void main(String[] args) { int x = 10; { int x = 20; System.out.println(x); } System.out.println(x); } }
Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());
Consider: class Parent { Parent() { System.out.println("P"); } } class Child extends Parent { Child() { System.out.println("C"); } } public static void main(String[] args) { new Child(); }
What is the output of: int x = 5; System.out.println(x++ + ++x);
What will be the output of: int x = 5; System.out.println(++x + x++);?
What is the result of: System.out.println('A' + 'B');?
What will happen in this code: int x = Integer.MAX_VALUE; x++;?
In the context of Java 2024-25 exam pattern, which statement about the enhanced 'var' keyword (local variable type inference) is INCORRECT?
What is the output of the following code snippet? int x = 10; int y = x++ + ++x; System.out.println(x + " " + y);
What will be the result of executing the following code? boolean result = (5 > 3) && ( > 5); System.out.println(result);
What will be the output? interface A { void show(); } class B implements A { public void show() { System.out.println("B"); } } class C extends B { public void show() { System.out.println("C"); } } A obj = new C(); obj.show();
What will be the output? class Test { int x = 5; { x = 10; } Test() { x = 15; } public static void main(String[] args) { Test t = new Test(); System.out.println(t.x); } }
What is the output? interface I1 { void method1(); } interface I2 extends I1 { void method2(); } class C implements I2 { public void method1() { System.out.println("M1"); } public void method2() { System.out.println("M2"); } } public class Test { public static void main(String[] args) { I1 obj = new C(); obj.method2(); } }
In Java, if a child class constructor does not explicitly call the parent class constructor using 'super()', what happens?