Career

31 OOP Interview Questions And Answers

A good Software developer should have good OOP (Objected Oriented Programming) concepts. If you have an interview for the position of Software developer, you should expect the OOP interview questions that I am going to share in the post below. Do not forget to bookmark this page as this might help you in future as well ūüôā

OOP Interview Questions And Answers

1. What is OOP?

OOP stands for Object-Oriented Programming. It is a programming paradigm in which everything is represented as an object and the program is designed using classes and objects.

2. What is an Object?

An Object is a real-world entity that has state and behavior like a bulb, chair, table etc.

3. What is a Class?

A Class is called the blueprint of an object.

4. What are the advantages of OOP? 

The advantages of OOP include re-usability and easy maintenance.

5. Difference between object-based and object-oriented programming?

Object-based Programming is almost the same methodology as the Object Oriented Programming but it does not support Inheritance. JavaScript is one of the examples of Object-based programming.

6. What is a Constructor?

It is a special type of method which invoked at the time of object creation.

7. What is the difference between Constructor and Method? 

A constructor must not have any return type and its name should be same as the Class name. A method must have return type while its name may or may not be same as the Class name.

8. Does Constructor return any value?

The constructor returns the class instance.

9. What are the pillars of OOP?

Inheritance, Polymorphism, Abstraction, and Encapsulation.

10. What is Inheritance?

It is a concept in which the child class inherits all the attributes and behaviors of its parent class.

11. What is Multiple Inheritance and Multilevel Inheritance? 

In multiple inheritance, a class inherits attributes and behaviors from multiple parent classes. In Multilevel inheritance, a class extends a class, which extends another class.

12. What is Aggregation?

When a class contains a reference to another class, this concept is called Aggregation.

13. When should opt for Inheritance and Aggregation?

When there is an IS-A relationship between the two entities, we will opt Inheritance. For example Cat and Animal (Cat is a(n) Animal. While, when there is a HAS-A relationship between the two entities, we will opt Aggregation. For Example Class and Student (Class has a Student).

14. What is the difference between Aggregation and Composition?

The composition is a strong association between two entities. For Example Car And Engine. It Car is destroyed, Engine is of no use. As compared to this, entities are independent of each other in Aggregation. For Example, Class, and Student. If Class is destroyed, Student can still exist.

15. What is Polymorphism?

In OOP, the ability of the objects to respond in a different manner to identical messages is called Polymorphism. It is achieved by method overloading and method overriding.

16. What is method overloading?

If two or more than two methods in the same class have the same name but different arguments, this concept is called method overloading.  It is also called static binding or compile time polymorphism.

17. What is method overriding?

If a method defined in a parent class is redefined in the child class, this concept is called method overriding. It is also called dynamic binding or runtime polymorphism.

18. What is Encapsulation?

Hiding the state or behavior of an object is called Encapsulation. It is achieved using access modifiers.

19. What are access modifiers?

Access modifiers are the keywords that define the scope of the attribute or the function.

20. What is Abstraction?

Hiding the certain complex details and showing the essential features of the object is called Abstraction.

21. What is an abstract method?

A method that is declared but has no definition.

22. What is a virtual method?

It is a member method of a class which is expected to be overridden in its derived or child class.

23. What is the difference between abstract and virtual method?

A virtual method can have a definition while abstract method can’t have any definition.

24. What is the use of the ‘static’ keyword?

If a variable or method is declared static, it gets associated with the class instead of the object. Static variables and methods can be called without the creation of the instance of the class they are in.

25. What is the use of the ‘Super’ keyword?

It is used to invoke the constructor of the parent class in the child class. It is also used to invoke the method defined in the parent class which is overridden in the child class.

26. What is the difference between abstraction and encapsulation?

Encapsulation is hiding the internal details of the object while abstraction is showing the essential features and hiding the internal complexity.

27. What is an Interface?

It is a contract that enforces a class to implement all the abstract methods declared in that interface.

28. What is the difference between abstract class and interface?

In the abstract class, partial abstraction is achieved (0-100%) while through the interface, 100% abstraction is achieved. All the methods in the interface are abstract while abstract class contains both abstract and non abstract methods.

29. Can Overloaded methods have different return types?

Yes, the compiler is smart enough to distinguish the methods with different return types but their arguments cant be same.

This will give a compile time error:
¬† ¬†public void calculate(int num) { …. }

¬† ¬†public int calculate(int num) { ….}¬†

However, this will be successfully compiled:

¬† ¬†public void calculate(int num) { …. }

¬† ¬†public int calculate(int num, int numExtra) { ….}¬†

30. Assume there is a parent class “Animal” and a child class “Cat”. Can the below code be executed?

    i) Animal a = new Cat ( );

This code can be executed as the parent class object can have a reference to the child class object.

    ii) Cat c = new Animal ( );

This code will throw an error as the child class object cannot have a reference to the parent class object.

31. What is a concrete class?

It is a class that does not define an abstract method of its own.

I hope the above OOP Interview questions will prove to be useful for you. If you like it, share it with your friends to whom you feel it will be useful. Best of Luck!

 
Comments

Latest

To Top