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

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

Q.182Hard

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

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

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

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

Q.186Hard

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

Q.187Hard

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

Q.188Easy

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

Q.189Easy

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

Q.190Medium

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

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

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

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

Q.194Medium

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

Q.195Hard

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

Q.196Hard

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

Q.197Hard

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

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

Q.199Hard

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

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?