OOP Interview Questions and Answers
Question - 41 : - What is a superclass?
Answer - 41 : -
A superclass or base class is a class that acts as a parent to some other class or classes. For example, the Vehicle class is a superclass of class Car.
Question - 42 : - What is a subclass?
Answer - 42 : -
A class that inherits from another class is called the subclass. For example, the class Car is a subclass or a derived of Vehicle class.
Question - 43 : - What is polymorphism?
Answer - 43 : -
Polymorphism refers to the ability to exist in multiple forms. Multiple definitions can be given to a single interface. For example, if you have a class named Vehicle, it can have a method named speed but you cannot define it because different vehicles have different speed. This method will be defined in the subclasses with different definitions for different vehicles.
Question - 44 : - What is static polymorphism?
Answer - 44 : -
Static polymorphism (static binding) is a kind of polymorphism that occurs at compile time. An example of compile-time polymorphism is method overloading.
Question - 45 : - What is dynamic polymorphism?
Answer - 45 : -
Runtime polymorphism or dynamic polymorphism (dynamic binding) is a type of polymorphism which is resolved during runtime. An example of runtime polymorphism is method overriding.
Question - 46 : - What is the use of ‘finalize’?
Answer - 46 : -
Finalize as an object method used to free up unmanaged resources and cleanup before Garbage Collection(GC). It performs memory management tasks.
Question - 47 : - What is a copy constructor?
Answer - 47 : -
A copy constructor creates objects by copying variables from another object of the same class. The main aim of a copy constructor is to create a new object from an existing one.
Question - 48 : - Types of constructors
Answer - 48 : -
Types of constructors differ from language to language. However, all the possible constructors are:
- Default constructor
- Parameterized constructor
- Copy constructor
- Static constructor
- Private constructor
Question - 49 : - What is a destructor?
Answer - 49 : -
A destructor is a method that is automatically invoked when an object is destroyed. The destructor also recovers the heap space that was allocated to the destroyed object, closes the files and database connections of the object, etc.
Question - 50 : - What is a constructor?
Answer - 50 : -
A constructor is a special type of method that has the same name as the class and is used to initialize objects of that class.