Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

476 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 391–400 of 476
Topics in Java Programming
Q.391 Medium OOP in Java
In Java, which of the following is true about abstract classes?
A An abstract class can have no abstract methods
B An abstract class must have all abstract methods
C An abstract class cannot have constructors
D An abstract class cannot have instance variables
Correct Answer:  A. An abstract class can have no abstract methods
EXPLANATION

An abstract class can have zero or more abstract methods. It can also have concrete methods, constructors, and instance variables.

Take Test
Q.392 Medium OOP in Java
What will happen if you try to override a final method in a subclass?
A It will compile and run successfully
B Compilation error will occur
C Runtime exception will be thrown
D It will override silently
Correct Answer:  B. Compilation error will occur
EXPLANATION

A final method cannot be overridden. Attempting to override it results in a compilation error: 'cannot override final method'.

Take Test
Q.393 Medium OOP in Java
Which of the following demonstrates proper method overloading in Java?
A public void display() { } and public int display() { }
B public void display(int a) { } and public void display(int b) { }
C public void display(int a) { } and public void display(String a) { }
D public void display() { } and public void display() { return 5; }
Correct Answer:  C. public void display(int a) { } and public void display(String a) { }
EXPLANATION

Method overloading requires different parameter types or number of parameters. Options A and D have different return types (not valid for overloading), and option B has the same signature with different parameter names (not overloading).

Take Test
Q.394 Medium OOP in Java
Which of the following correctly demonstrates composition over inheritance?
A class Engine { } class Car extends Engine { }
B class Engine { } class Car { Engine e = new Engine(); }
C Both approaches are equally good
D Composition is never preferred in Java
Correct Answer:  B. class Engine { } class Car { Engine e = new Engine(); }
EXPLANATION

Composition (HAS-A relationship) is often preferred over inheritance (IS-A relationship) because it's more flexible and avoids tight coupling.

Take Test
Q.395 Medium OOP in Java
Which of the following is true about interface default methods?
A They must be implemented by all implementing classes
B They provide a default implementation that can be overridden or inherited
C They are the same as abstract methods
D Only one interface can have default methods
Correct Answer:  B. They provide a default implementation that can be overridden or inherited
EXPLANATION

Default methods in interfaces (Java 8+) provide a default implementation. Implementing classes can use this default implementation or override it as needed.

Take Test
Q.396 Medium OOP in Java
What is the relationship between an abstract class and an interface in Java 8+?
A Abstract classes and interfaces are identical
B Interfaces can have default and static methods, while abstract classes can have instance variables and constructors
C Only abstract classes can be extended
D Interfaces are always preferred over abstract classes
Correct Answer:  B. Interfaces can have default and static methods, while abstract classes can have instance variables and constructors
EXPLANATION

From Java 8, interfaces can have default and static methods, but abstract classes can have instance variables, constructors, and private methods which interfaces cannot have.

Take Test
Q.397 Medium OOP in Java
Consider a scenario where class B extends class A. If class A has a constructor with parameters, what must class B do?
A Ignore the parent constructor completely
B Must explicitly call parent constructor using super()
C Parent constructor is automatically called without any action
D Class B becomes invalid and cannot be compiled
Correct Answer:  B. Must explicitly call parent constructor using super()
EXPLANATION

If a parent class has a parameterized constructor and no default constructor, the child class must explicitly call it using super() to initialize parent class members.

Take Test
Q.398 Medium OOP in Java
What is the difference between 'this' and 'super' keywords?
A 'this' refers to parent class and 'super' refers to current class
B 'this' refers to current class instance and 'super' refers to parent class
C They are interchangeable
D 'super' is used only in abstract classes
Correct Answer:  B. 'this' refers to current class instance and 'super' refers to parent class
EXPLANATION

'this' is a reference to the current object instance, while 'super' is a reference to the parent class. They serve different purposes in inheritance hierarchy.

Take Test
Q.399 Medium OOP in Java
Which of the following statements about the 'final' keyword is correct?
A A final class can be extended
B A final method can be overridden
C A final variable's value cannot be changed after initialization
D A final class can implement multiple interfaces
Correct Answer:  C. A final variable's value cannot be changed after initialization
EXPLANATION

The 'final' keyword when applied to a variable makes it a constant. When applied to a class, it cannot be extended. When applied to a method, it cannot be overridden.

Take Test
Q.400 Medium OOP in Java
What is the output of the following code?
class Parent { void show() { System.out.println("Parent"); } }
class Child extends Parent { void show() { System.out.println("Child"); } }
public class Test { public static void main(String[] args) { Parent p = new Child(); p.show(); } }
A Parent
B Child
C Compile-time error
D Runtime error
Correct Answer:  B. Child
EXPLANATION

This demonstrates runtime polymorphism. Although the reference is of type Parent, the actual object is Child. The overridden show() method in Child class is executed.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips