• +91 9723535972
  • info@interviewmaterial.com

OOP Interview Questions and Answers

OOP Interview Questions and Answers

Question - 81 : - Explain Inheritance with an example?

Answer - 81 : -

Inheritance is one of the major features of object-oriented programming, by which an entity inherits some characteristics and behaviors of some other entity and makes them their own. Inheritance helps to improve and facilitate code reuse.

Let me explain to you with a common example. Let's take three different vehicles - a car, truck, or bus. These three are entirely different from one another with their own specific characteristics and behavior. But. in all three, you will find some common elements, like steering wheel, accelerator, clutch, brakes, etc. Though these elements are used in different vehicles, still they have their own features which are common among all vehicles. This is achieved with inheritance. The car, the truck, and the bus have all inherited the features like steering wheel, accelerator, clutch, brakes, etc, and used them as their own. Due to this, they did not have to create these components from scratch, thereby facilitating code reuse.

Question - 82 : - Are there any limitations of Inheritance?

Answer - 82 : -

Yes, with more powers comes more complications. Inheritance is a very powerful feature in OOPs, but it has some limitations too. Inheritance needs more time to process, as it needs to navigate through multiple classes for its implementation. Also, the classes involved in Inheritance - the base class and the child class, are very tightly coupled together. So if one needs to make some changes, they might need to do nested changes in both classes. Inheritance might be complex for implementation, as well. So if not correctly implemented, this might lead to unexpected errors or incorrect outputs.

Question - 83 : - What are the various types of inheritance?

Answer - 83 : -

The various types of inheritance include:

  • Single inheritance
  • Multiple inheritances
  • Multi-level inheritance
  • Hierarchical inheritance
  • Hybrid inheritance

Question - 84 : - What is meant by static polymorphism?

Answer - 84 : -

Static Polymorphism is commonly known as the Compile time polymorphism. Static polymorphism is the feature by which an object is linked with the respective function or operator based on the values during the compile time. Static or Compile time Polymorphism can be achieved through Method overloading or operator overloading.

Question - 85 : - What is meant by dynamic polymorphism?

Answer - 85 : -

Dynamic Polymorphism or Runtime polymorphism refers to the type of Polymorphism in OOPs, by which the actual implementation of the function is decided during the runtime or execution. The dynamic or runtime polymorphism can be achieved with the help of method overriding.

Question - 86 : - What is the difference between overloading and overriding?

Answer - 86 : -

Overloading is a compile-time polymorphism feature in which an entity has multiple implementations with the same name. For example, Method overloading and Operator overloading.

Whereas Overriding is a runtime polymorphism feature in which an entity has the same name, but its implementation changes during execution. For example, Method overriding.

Question - 87 : - How is data abstraction accomplished?

Answer - 87 : -

Data abstraction is accomplished with the help of abstract methods or abstract classes.

Question - 88 : - How is an abstract class different from an interface?

Answer - 88 : -

Interface and abstract class both are special types of classes that contain only the methods declaration and not their implementation. But the interface is entirely different from an abstract class. The main difference between the two is that, when an interface is implemented, the subclass must define all its methods and provide its implementation. Whereas when an abstract class is inherited, the subclass does not need to provide the definition of its abstract method, until and unless the subclass is using it.

Also, an abstract class can contain abstract methods as well as non-abstract methods.

Question - 89 : - What are access specifiers and what is their significance?

Answer - 89 : -

Access specifiers, as the name suggests, are a special type of keywords, which are used to control or specify the accessibility of entities like classes, methods, etc. Some of the access specifiers or access modifiers include “private”, “public”, etc. These access specifiers also play a very vital role in achieving Encapsulation - one of the major features of OOPs.

Question - 90 : - What is meant by exception handling?

Answer - 90 : -

No one wants its software to fail or crash. Exceptions are the major reason for software failure. The exceptions can be handled in the program beforehand and prevent the execution from stopping. This is known as exception handling.
So exception handling is the mechanism for identifying the undesirable states that the program can reach and specifying the desirable outcomes of such states.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners