OOPS: Interview Questions

What are the advantages of Object Oriented languages?

As Object defines real worlds entity so that OOPS gives clear structure of the program,simplifies complex design,every feature of OOPS give their own benefits.

Simplicity is the most important advantage of OOPS as it deals with the object directly. 

Data Hiding is the another advantage of OOPS, it maintains the accessibility of object's data from other objects.

Re-usability is the feature where we can re-use any class, methods . It improves code quality.

Modifiable and Extensible can modify/extend in the existing code easily, abstraction, interfaces are useful to provide such base layer to application.

Maintainability is another advantage OOPS features makes our code more manageable.

What is the difference between object oriented and object based language?

Object oriented languages support oops concepts but object based object languages don’t support Polymorphism and Inheritance. Object based languages work on built –in objects.

Java, C++ are object oriented and Vb-script, JavaScript are object based languages.

What are Object and Class and how they relate?

Object is and entity, in Object Oriented programming language we design program for any specific entity that has its own properties and functions and both (properties and functions) are defined in a body called class. Class is also known as blueprint of an object.

What is Diamond Problem in Inheritance?

Diamond problem is exactly an ambiguity issue that comes in case of multiple inheritance.Let's understand with the diagram,

Diamond problem in inheritance. ByTechAchievers.com

As per the diagram B and C are inheriting A and again B and C are inherited by D. This will cause the ambiguity between the data that means different values can have same representation this would create incorrect data values and would impact on quality of code. This is the reason why java does not support multiple inheritance.

What is difference between Compile Time and Run Time Polymorphism?

Compile-Time polymorphism is the Method Overloading where same name method can perform in different ways within the class. Here all methods are associated with same class and methods will be call by class object at compile time. 

Run-Time polymorphism is the Method Overriding where same name method can be implemented within the parent and child class, so that compiler gets confuse which method is calling, to call the methods objects will be assigned at. run time.

What is difference between Static Binding and Dynamic Binding in Polymorphism?

Compile-Time polymorphism also known as Static Binding Polymorphism. When we call method of the class then compiler knows about the class object and method calls by the object itself (statically) known as static binding polymorphism.

Run-Time polymorphism also known as Dynamic Binding Polymorphism. When we call method of the sub class then compiler gets confuse which method should call base class or sub class so that to call the methods objects will be assigned dynamically this is known as dynamic binding polymorphism.

What is difference between Abstract class and Interface?


Abstract class is a base class for its sub classes to provide methods to be implemented by its sub classes.

Interface is the interface that also provide methods to be implemented by its sub classes.

Both cannot be initialized as both have been designed to provide base layer to the program. 


Abstract classes are declared by abstract keyword.

Interface are declared by interface keyword.


Abstract class do have abstract methods (with no body) and concrete (non-abstract, like other methods) methods.Abstract class may have static fields and methods.

Interface do have abstract methods if it has variable the it should be public static final.


Abstract class does not support multiple inheritance or sub class can extend only one abstract class. 

Interface does support multiple interface , sub class can implements more then on interfaces.

How to decide what should I use in program in between Abstract class and Interface?

When use abstract class,

When we want to declare non-static, non-final fields in a base class so that their state can be change by methods.

When yow want to share data among co-related sub classes.

Abstract class are designed to provide the implementation to sub classes. 

When use Interface 

Interface are designed to provide operation to any class.

Any unrelated class can implement interface and can use its operations like comparable , clonable , seriaziable etc.

Using Interface we can use multiple inheritance feature.

No comments

Powered by Blogger.