Java OOPs Interview Questions and Answers

Hello coders, welcome back to codingbroz !!! Today we are back with interesting and most important Java OOPs interview questions that every computer science student and engineer must know. These are some important Java OOPs interview questions which are generally asked in many technical interview in software companies.

Object oriented Programming is the base of every modern programming language that exists today like python, c++, java etc. So, it becomes very important to know the basics of Object oriented Programming and these Java OOPs interview questions are important if you want to get a Java developer job or want to become a good Java programmer.

Object oriented Programming is the fundamental of programming which is taught to every computer science student in their college. Now, lets see want are those Java OOPs interview questions that maybe get asked in your next coding interview or coding test.

Important Java Object Oriented Programming Interview Questions :

What are some core concepts of OOPS in java?
Answer: Core concepts of OOPs are :
Polymorphism
Abstraction
Encapsulation
Inheritance

What is Abstraction?
Answer: Abstraction is a concept of showing only important information and hiding its implementation.This is one of the most asked Oops interview questions as it checks basic oops concepts for java programmers.
For example:
When you see a car, you know it is running but how it running internally, you may not aware of it.
This is Abstraction. You just expose required details.

What is encapsulation?
Answer:
Encapsulation is process of wrapping data and function into single unit. You can use access modifier for variables, so other classes may not access it directly but it can be accessed only through public methods of the class. You can create class fully encapsulated using private variables.

What is difference between Abstraction and Encapsulation?
Answer:
Abstraction is a concept of showing only important information and hiding its implementation where as Encapsulation provides a barrier to access of data and methods.
Abstraction is more about design concept and Encapsulation is about implementation.

What is Polymorphism in java?
Answer:
Polymorphism means one name many forms. It is concept by which you can perform same action in different ways.

What are types of Polymorphism in java?
Answer:
There are two type of polymorphism in java.

  • Compile time polymorphism
  • Run time polymorphism

What are ways by which you can implement polymorphism in java?
Answer:
You can implement polymorphism using

  • Method overloading
  • Method overriding

What is inheritance in java?
Answer:
Inheritance allows use of properties and methods of another class (Parent class), so you can reuse all methods and properties.

What is multiple inheritance?
Answer:
When child class can inherit from multiple parent classes. This mechanism is known as multiple inheritance.

What is diamond problem in case of multiple inheritance?
Answer:
Let’s understand this with the help of simple example.
Let’s assume:
Class A has two child classes B and C.
Class D has two parent classes B and C.
methodCommon() of A is overridden by classes B and C.
When you call methodCommon() on instance of D, which method should get called(From class B or C)
Above problem is known as diamond problem in the context of multiple inheritance.

Why java does not support multiple inheritance?
Answer:

Java avoided multiple inheritance due to diamond problem and to make it less complex.

What is constructor in java?
Answer:
A constructor is block of code which allows you to create instance of the object. It does not have return type.
It has two main points –
Constructor name should be same as class
Constructor should not have any return type else it will be same as method.

Can we declare constructor as final?
Answer:
No, Constructor can not be declared as final. If you do so, you will get compile time error.

What is Static Binding and Dynamic Binding?
Answer:
Static binding is resolved at compile time. Method overloading is perfect example of static binding.
Dynamic binding is resolved at run time. Method overriding is perfect example of dynamic binding.

What is association?
Answer:
Association is relationship between two objects. It defines multiplicities between two objects such as one to one, one to many, many to many.
For example:
Student and Professor

What is aggregation?
Answer:
Aggregation is the special form of association. It is also called as “has-a” relationship. If One object contains another object, it is considered as aggregation.
For example:
Car has a tyre.

What is composition?
Answer:
Composition is special type of aggregation. You may consider it as “restricted aggregation” If object contains another object and contained object can not exist without container object then this relationship is known as composition. This is one of the most asked Oops interview questions.
For example:
Car has a engine. Engine can not exist without a car.

That’s all about Oops interview questions.

Today you learned about the important OOPs concepts and questions in Java that will definitely help you get a good job and will make you a good software engineer !!!

Leave a Comment

Your email address will not be published. Required fields are marked *