iGET

Java Programming - MCQ Practice Questions

Java interviews and campus tests lean heavily on object oriented behaviour rather than API recall. This set covers inheritance and polymorphism, interfaces and abstract classes, the collections framework, exception handling, multithreading, string handling, and JVM basics such as garbage collection. Output based questions are included because they expose the gaps that theory questions hide.

951 questions | 100% Free

Q.1Hard

Consider the code: int a = 5; int b = a++; System.out.println(a + " " + b); What is the output?

Q.2Hard

What will be printed? System.out.println(10 + 20 + "Java");

Q.3Hard

What is the scope of a local variable in Java?

Q.4Hard

Consider: int x = 0; System.out.println(x == 0 && x != 1); What is the output?

Q.5Hard

What is the result of: int x = 5; System.out.println(x++ + ++x);?

Q.6Hard

Which statement about Java's garbage collection is true?

Q.7Hard

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); } }

Q.8Hard

Which of the following will throw a NullPointerException? String s = null; System.out.println(s.length());

Q.9Hard

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(); }

Q.10Hard

What is the output of: int x = 5; System.out.println(x++ + ++x);

Q.11Hard

What will be the output of: int x = 5; System.out.println(++x + x++);?

Q.12Hard

What is the result of: System.out.println('A' + 'B');?

Q.13Hard

What will happen in this code: int x = Integer.MAX_VALUE; x++;?

Q.14Hard

In the context of Java 2024-25 exam pattern, which statement about the enhanced 'var' keyword (local variable type inference) is INCORRECT?

Q.15Hard

What will be the result of executing the following code?
boolean result = (5 > 3) && ( > 5);
System.out.println(result);

Q.16Hard

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();

Q.17Hard

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);
}
}

Q.18Hard

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();
}
}

Q.19Hard

In Java, if a child class constructor does not explicitly call the parent class constructor using 'super()', what happens?

Q.20Hard

A developer needs to create a class that cannot be extended and whose instances are immutable. Which keywords should be used?