Basic OOPs Interview Questions

Basic OOPs Interview Questions –

1. Are there any limitations of inheritance? If yes, then what?

Yes. The limitations of inheritance are:

  1. Increased execution effort and time
  2. Tight coupling of parent and child class
  3. Requires correct implementation
  4. Requires jumping between different classes
Basic OOPs Interview Questions

2. Define virtual functions.

The functions that help achieve runtime polymorphism are a part of functions present in the parent class and overridden by a subclass. 

3. List down the limitations of Object-Oriented programming. 

  1. It requires intensive testing
  2. Not apt for minor problems
  3. It requires good planning
  4. It takes more time to solve problems
  5. Problems need to be thought in term of objects

4. What is the difference between a base class and a superclass?

The base class is the root class- the most generalized class. At the same time, the superclass is the immediate parent class from which the other class inherits.

5. What is the access modifier for methods inside an interface?

All the methods inside an interface are public by default, and no other modifier can be specified.

6. Explain the concept of inheritance with a real-life example.

The parent class is a logical concept, such as a vehicle is a base class that defines the common properties shared by all vehicles. However, child classes are a more specific type of class such as truck, bus, car, etc. Inheritance allows subclasses to inherit common attributes of a vehicle and define specific attributes and methods to their own.

7. How is a structure different from a class?

A structure is a user-defined collection of variables having different data types. However, it is not possible to instantiate a structure or inherit from it. Thus, it’s not an OOPs concept.

Read Also – Sonarqube for static code analysis

8. What is an abstract function?

An abstract function is a function declared only in the base class. It is redefined in the subclass as it does not contain any definition in the base class.

9. Name three operators that can’t be overloaded.

  •  “::” Scope resolution operator
  • “. *” Pointer to member operator
  •  “.” dot or Member access operator

10. How is encapsulation different from data abstraction?

Data abstraction refers to the ability to hide unwanted information. At the same time, encapsulation refers to hiding data as well as the method together. 

11. Why do we need to use OOPs?

OOPs needs to be used for:

  1. making programming clearer and problem-solving more concise
  2. reusing code with the help of inheritance
  3. reducing redundancy
  4. encapsulation
  5. data hiding
  6. the division into subproblems
  7. program flexibility using polymorphism

12. What is multiple inheritance?

If one class shares the behavior and structure defined in another multiple class, it is called multiple inheritance.

13. Give an example of encapsulation. 

The notion of data hiding is referred to as encapsulation. Protected and private members in C++ are examples.

14. What is the difference between overloading and overriding?

Overloading is two or more methods having the same name but different parameters. It is solved during compile-time. Whereas, Overriding is an OOPs concept that allows sub-classes to have a specific implementation of a method already provided by its parent class. It is solved during runtime.

15. Define protected access modifier.

A protected access modifier is accessible by own class and accessible by derived class but not accessible by the world.

16. What is the function of a super keyword?

The super keyword keyword is used to forward a constructor’s call to a constructor in the superclass. It invokes the overridden method that allows access to these methods and the superclass’s hidden members.

17. What is compile time polymorphism?

When a polymorphic call is made, and the compiler knows which function is to be called; this is known as compile-time polymorphism. The features like function default arguments, overloading, and templates in C++ support compile-time polymorphism. 

18. How can you call a base class method without creating an instance?

It is possible to call the base class without instantiation if it’s a static method and some other subclass has inherited the base class. 

19. One of the key OOPs interview questions could be to give a real-life example of data abstraction. 

While driving a car, you know that on pressing the accelerator, the speed will increase. However, you do not know precisely how it happens. This is an example of data abstraction as the implementation details are concealed from the driver.

20. What is the purpose of ‘this’ keyword?

To refer to the current object of a class, this keyword is used. It is used as a pointer that differentiates between the global object and the current object by referring to the current one.

Basic OOPs Interview Questions
Mahesh Wabale
Latest posts by Mahesh Wabale (see all)

Leave a Comment