Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java OOPs Interview Questions and Answers

Ques 11. What is the purpose of the 'static' keyword in Java?

The 'static' keyword is used to create class-level variables and methods. These belong to the class rather than instances of the class.

Example:

static int count = 0;
static void increment() { count++; }

Is it helpful? Add Comment View Comments
 

Ques 12. Explain the concept of composition in Java.

Composition involves creating complex objects by combining simpler objects. It allows for better code organization and reusability.

Example:

class Car {
  Engine engine;
  // other properties and methods
}

Is it helpful? Add Comment View Comments
 

Ques 13. What is the purpose of the 'interface' in Java?

An interface in Java is a collection of abstract methods that defines a contract for classes to implement. It supports multiple inheritances and is often used for achieving abstraction.

Example:

interface Printable { void print(); }

Is it helpful? Add Comment View Comments
 

Ques 14. Explain the 'diamond problem' and how Java solves it.

The 'diamond problem' occurs in multiple inheritance when a class inherits from two classes that have a common ancestor. In Java, this is avoided by allowing a class to implement multiple interfaces.

Is it helpful? Add Comment View Comments
 

Ques 15. What is the purpose of the 'final' method in Java?

A 'final' method in Java cannot be overridden by subclasses. It is used to prevent modification of a method in a subclass.

Example:

class Parent {
  final void display() { /* method implementation */ }
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook