In this post, we will see most important Oops interview questions in java.
1. What are some core concepts of OOPS in java?
Core concepts of OOPs are :
2. What is Abstraction?
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.
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.
3. What is encapsulation?
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.
4. What is difference between Abstraction and Encapsulation?
- 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.
5. What is Polymorphism in java?
Polymorphism means one name many forms. It is concept by which you can perform same action in different ways.
6. What are types of Polymorphism in java?
There are two type of polymorphism in java.
- Compile time polymorphism
- Run time polymorphism
7. What are ways by which you can implement polymorphism in java?
- Method overloading
- Method overriding
8. What is inheritance in java?
Inheritance allows use of properties and methods of another class (Parent class), so you can reuse all methods and properties.
9.What is multiple inheritance?
When child class can inherit from multiple parent classes.This mechanism is known as multiple inheritance.
10. What is diamond problem in case of multiple inheritance?
Let’s understand this with the help of simple example.
- Class A has two child classes B and C.
- Class D has two parent classes B and C.
- methodCommon() of A is overriden by classes B and C.
- When you call methodCommon() on instance of D, which method should get called(From class B or C)
11. Why java does not support multiple inheritance?
12. What is constructor in java?
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.
13. Can we declare constructor as final?
No, Constructor can not be declared as final. If you do so, you will get compile time error.
14.What is Static Binding and Dynamic Binding?
Static binding is resolved at compile time. Method overloading is perfect example of static binding.
Dynamic binding is resolved at run time. Method overridng is perfect exmple of dynamic binding.
15. What is association?
Association is relationship between two objects. It defines multiplicities between two objects such as one to one, one to many, many to many.
Student and Professor
16. What is aggregation?
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.
Car has a tyre.
17. What is composition?
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.
Car has a engine. Engine can not exist without a car.
That’s all about Oops interview questions.
You may also like:
- Core java interview questions
- Java Collections interview questions
- Java String interview questions
- Java Multithreading interview questions
- Exceptional handling interview questions in java
- Java Serialization interview questions in java
- Method overloading and overriding interview questions
- web services interview questions
- restful web services interview questions
- Data structure and algorithm Interview Questions
- Spring interview questionsHibernate interview questions