OOP Interview Questions and Answers
Question - 51 : - What are pure virtual functions?
Answer - 51 : -
Pure virtual functions or abstract functions are functions that are only declared in the base class. This means that they do not contain any definition in the base class and need to be redefined in the subclass.
Question - 52 : - What are virtual functions?
Answer - 52 : -
Virtual functions are functions that are present in the parent class and are overridden by the subclass. These functions are used to achieve runtime polymorphism.
Question - 53 : - What is an interface?
Answer - 53 : -
It is a concept of OOPs that allows you to declare methods without defining them. Interfaces, unlike classes, are not blueprints because they do not contain detailed instructions or actions to be performed. Any class that implements an interface defines the methods of the interface.
Question - 54 : - Can you create an instance of an abstract class?
Answer - 54 : -
No. Instances of an abstract class cannot be created because it does not have a complete implementation. However, instances of subclass inheriting the abstract class can be created.
Question - 55 : - How to achieve data abstraction?
Answer - 55 : -
Data abstraction can be achieved through:
- Abstract class
- Abstract method
Question - 56 : - What is data abstraction?
Answer - 56 : -
Data abstraction is a very important feature of OOPs that allows displaying only the important information and hiding the implementation details. For example, while riding a bike, you know that if you raise the accelerator, the speed will increase, but you don’t know how it actually happens. This is data abstraction as the implementation details are hidden from the rider.
Question - 57 : - What are ‘access specifiers’?
Answer - 57 : -
Access specifiers or access modifiers are keywords that determine the accessibility of methods, classes, etc in OOPs. These access specifiers allow the implementation of encapsulation. The most common access specifiers are public, private and protected. However, there are a few more which are specific to the programming languages.
Question - 58 : - What is encapsulation?
Answer - 58 : -
Encapsulation refers to binding the data and the code that works on that together in a single unit. For example, a class. Encapsulation also allows data-hiding as the data specified in one class is hidden from other classes.
Question - 59 : - What is operator overloading?
Answer - 59 : -
Operator overloading refers to implementing operators using user-defined types based on the arguments passed along with it.
Question - 60 : - What is method overriding?
Answer - 60 : -
Method overriding is a feature of OOPs by which the child class or the subclass can redefine methods present in the base class or parent class. Here, the method that is overridden has the same name as well as the signature meaning the arguments passed and the return type.