Java OOPS interview questions and answers

Java OOPS interview questions

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 :

  • Polymorphism
  • Abstraction
  • Encapsulation
  • Inheritance

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.
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.

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?

You can implement polymorphism using
  • 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?

Answer:
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?

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 overriden 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.

11. Why java does not support multiple inheritance?

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

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?

Answer:
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?

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

16. 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.

17. 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.
You may also like:

Related Posts

  • Hibernate interview questions
    16 April

    Top 40+ Hibernate interview questions and answers

    Table of Contents1. What is ORM?2. What is Hibernate?3. What are advantages of Hibernate?4. Explain architecture of Hibernate?5. What are some core interfaces of hibernate?6. Explain brief about Session interface used in hibernate?7. Are session objects thread safe?8. Explain brief about SessionFactory object used in hibernate?9. What is Configuration class in hibernate?10. Explain brief about […]

  • Java Interview questions
    22 May

    Java interview questions

    Table of ContentsCore JavaCore java interview questionsCollections interview questionsMultithreading interview questionsJava 8 interview questionsOOPs interview questionsException Handling interview questionsString interview questionsSerialization interview questionsmethod overloading and method overriding interview questionsImmutable class interview questionsJava tricky interview questions Basic interview questions for fresher Interview questions for 5 to 7 years experiencedHow HashMap works in java? Difference between Interface […]

  • Solid principles in java
    09 November

    SOLID Principles in Java

    Table of ContentsWhat is the meaning of S.O.L.I.D?Single Responsibility Principle (SRP)Open Closed Principle Liskov Substitution Principle Interface Segregation PrincipleDependency Inversion PrincipleWrap Up In this post, we will see 5 SOLID Principles in Java. Robert C. Martin gave five objected oriented design principles, and the acronym S.O.L.I.D is used for it. Each letter of this acronym […]

  • Java interview questions for 2 years experience
    08 November

    Java interview questions for 2 years experience

    Table of Contents1.   Can we override static method in java?2.   Can you overload main method in java?3. Can we override private methods in java?4. What is the base class for all the classes?5.   Can you list down some of important method from object class?6.   Which two methods should you override while putting the custom object as […]

  • Java interview questions for 5 years experience
    08 November

    Java interview questions for 5 years experience

    Table of Contents1. Guess the output of below program.2. Guess the output of below program.3. Guess the output of below program.4. What will happen in case of below program?5. What will happen in case of below program?6. What will happen in case of below program?7. Guess the output of below program.8. Guess the output of […]

  • Java tricky interview questions
    11 September

    Java technical interview questions

    Table of Contents1 How HashMap works in java?2 Which methods you should implement for key Object in HashMap?3. Guess the output of below program.4. Guess the output of below code.5. What are differences between Comparator and Comparable?6. What is difference between Error and Exception?7. What is ClassLoader in java?8. What are types of ClassLoader in java?9. […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.