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
Which feature of Java ensures that a child class can have a method with a wider return type than the parent class?
What is the key difference between composition and inheritance in object design?
You need to create a class that provides common functionality for all database operations (insert, update, delete). What is the best approach?
In Java 16+, which sealed class feature allows you to restrict which classes can extend a class?
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();
Which of the following correctly implements the Factory Design Pattern principle in OOP?
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?