Basic OOPs Interview Questions –
1. Are there any limitations of inheritance? If yes, then what?
Yes. The limitations of inheritance are:
- Increased execution effort and time
- Tight coupling of parent and child class
- Requires correct implementation
- Requires jumping between different classes
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.
- It requires intensive testing
- Not apt for minor problems
- It requires good planning
- It takes more time to solve problems
- 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:
- making programming clearer and problem-solving more concise
- reusing code with the help of inheritance
- reducing redundancy
- encapsulation
- data hiding
- the division into subproblems
- 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.
- AnchorSetup using Docker-Compose - October 18, 2024
- Devops assignment - October 17, 2024
- Deployment of vault HA using MySQL - September 18, 2024