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

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

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

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

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

Q.185Hard

Which feature of Java ensures that a child class can have a method with a wider return type than the parent class?

Q.186Hard

What is the key difference between composition and inheritance in object design?

Q.187Easy

What is the default access modifier for a class member in Java if no modifier is specified?

Q.188Easy

Which keyword is used to prevent a class from being subclassed in Java?

Q.189Medium

In Java, if a parent class has a method void display() and a child class overrides it as void display(int x), what is this called?

Q.190Medium

Consider a scenario where you have an interface Shape with a method calculateArea(). You implement this in classes Circle and Rectangle. Which OOP concept is being demonstrated?

Q.191Medium

What will be printed when this code executes?
class A { int x = 5; }
class B extends A { int x = 10; }
public class Test {
public static void main(String[] args) {
A a = new B();
System.out.println(a.x);
}
}

Q.192Medium

Which of the following statements about 'this' keyword in Java is INCORRECT?

Q.193Medium

In Java, a class can implement multiple interfaces but can extend only one class. This design choice primarily supports which principle?

Q.194Hard

You need to create a class that provides common functionality for all database operations (insert, update, delete). What is the best approach?

Q.195Hard

In Java 16+, which sealed class feature allows you to restrict which classes can extend a class?

Q.196Hard

A system has classes: Vehicle -> Car -> ElectricCar. If Vehicle.start() is overridden in Car and again in ElectricCar, what is the output of: Vehicle v = new ElectricCar(); v.start();

Q.197Hard

Which of the following correctly implements the Factory Design Pattern principle in OOP?

Q.198Hard

In a banking system, Account is a parent class with method withdraw(). SavingsAccount and CurrentAccount both override it. A programmer writes: List<Account> accounts = new ArrayList<>(); accounts.add(new SavingsAccount()); accounts.add(new CurrentAccount()); for(Account a : accounts) a.withdraw(1000); Which concept is primarily demonstrated here?

Q.199Medium

In Java, when you override a method from a parent class, which of the following is NOT a valid reason to use the @Override annotation?

Q.200Easy

Which interface does HashMap implement in Java Collections Framework?