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

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

Q.82Hard

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

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

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

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

Q.86Hard

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

Q.87Hard

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

Q.88Easy

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

Q.89Easy

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

Q.90Medium

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.91Medium

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.92Medium

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.93Medium

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

Q.94Medium

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

Q.95Hard

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

Q.96Hard

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

Q.97Hard

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

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

Q.99Hard

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.100Medium

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?