Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 781–790 of 958
Topics in Java Programming
Q.781 Medium OOP in Java
Which statement about Java interfaces is INCORRECT according to 2024 specifications?
A Interfaces can have static methods
B Interfaces can have default methods
C Interfaces can have private methods
D Interfaces can be instantiated directly
Correct Answer:  D. Interfaces can be instantiated directly
EXPLANATION

Interfaces cannot be instantiated directly. Since Java 8, interfaces can have static and default methods, and since Java 9, they can have private methods.

Take Test
Q.782 Medium OOP in Java
What is the correct way to call a parent class constructor from a child class?
A parent();
B super();
C this.parent();
D ParentClass();
Correct Answer:  B. super();
EXPLANATION

The super() keyword is used to call the parent class constructor. It must be the first statement in the child class constructor.

Take Test
Q.783 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.784 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.785 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.786 Easy OOP in Java
Can you instantiate an interface in Java?
A Yes, directly with new keyword
B No, interfaces cannot be instantiated
C Yes, only if it has default methods
D Yes, if it has only abstract methods
Correct Answer:  B. No, interfaces cannot be instantiated
EXPLANATION

Interfaces cannot be instantiated directly. You can only create objects of classes that implement interfaces.

Take Test
Q.787 Easy OOP in Java
Which keyword is used to prevent a class from being subclassed?
A abstract
B final
C sealed
D static
Correct Answer:  B. final
EXPLANATION

The 'final' keyword prevents a class from being extended. For example: final class MyClass {} cannot be subclassed.

Take Test
Q.788 Easy OOP in Java
What is the default access modifier for class members in Java if not explicitly specified?
A public
B private
C protected
D package-private (default)
Correct Answer:  D. package-private (default)
EXPLANATION

If no access modifier is specified for a class member, it has package-private (default) access, meaning it's accessible only within the same package.

Take Test
Q.789 Easy OOP in Java
What is the access modifier of members declared in an interface?
A private
B protected
C public
D package-private
Correct Answer:  C. public
EXPLANATION

All members in an interface are implicitly public. Variables are public static final, and methods are public abstract (unless default or static).

Take Test
Q.790 Hard OOP in Java
In a legacy system, you find code with very deep inheritance hierarchy (5+ levels). What design problem does this indicate?
A Good object-oriented design
B Violation of the Liskov Substitution Principle
C Possible violation of 'favor composition over inheritance' principle
D The code is efficient and should be kept as is
Correct Answer:  C. Possible violation of 'favor composition over inheritance' principle
EXPLANATION

Deep inheritance hierarchies are considered a code smell. They suggest that composition might have been a better approach, leading to tighter coupling and reduced flexibility.

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