iGET

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

Q.1Hard

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.2Hard

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.3Hard

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.4Hard

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

Q.5Hard

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

Q.6Hard

When a static method is called on an instance of a class, what happens?

Q.7Hard

A company's codebase has a scenario where multiple unrelated classes need to implement a contract with specific methods. Which design choice is best?

Q.8Hard

What is the output of this code? class A { int x = 10; } class B extends A { int x = 20; } public class Test { public static void main(String[] args) { A a = new B(); System.out.println(a.x); } }

Q.9Hard

In Java, can you create an object of an abstract class?

Q.10Hard

What is the main difference between method overriding and method overloading?

Q.11Hard

What does the following code output? class A { static void display() { System.out.println("A"); } } class B extends A { static void display() { System.out.println("B"); } } public class Test { public static void main(String[] args) { A ref = new B(); ref.display(); } }

Q.12Hard

A real-world scenario: You're designing a banking system. Should you use an abstract class or interface for 'Account'?

Q.13Hard

What happens with exception handling in method overriding?

Q.14Hard

What is the output of the following code? interface I1 { default void show() { System.out.println("I1"); } } interface I2 { default void show() { System.out.println("I2"); } } class C implements I1, I2 { public void show() { I1.super.show(); } public static void main(String[] args) { new C().show(); } }

Q.15Hard

In a legacy system, you find code with very deep inheritance hierarchy (5+ levels). What design problem does this indicate?

Q.16Hard

Which of the following best demonstrates the Liskov Substitution Principle in OOP?

Q.17Hard

Design scenario: You need to create a payment system where Credit Card, Debit Card, and UPI are payment methods. What's the best OOP approach?

Q.18Hard

What will be the compilation result of this code? interface A { void method(); } interface B { void method(); } class C implements A, B { public void method() { } }

Q.19Hard

In a real-world e-commerce system, you want to prevent direct instantiation of a base Product class but allow creation of Laptop, Mobile, and Tablet. Which approach is best?

Q.20Hard

What is the correct order of execution when you create an object in a multi-level inheritance hierarchy?