OOPs Interview Questions and Answers
Ques 26. What is the role of the 'super()' statement in a constructor?
The 'super()' statement is used in a subclass constructor to call the constructor of its superclass. It initializes the inherited properties and ensures that the superclass's constructor is executed before the subclass's constructor.
Example:
class Subclass extends Superclass {
constructor() {
super();
}
}
Ques 27. What is an abstract class in C#?
In C#, an abstract class is a class that cannot be instantiated and may contain abstract methods. It is used to provide a common base for related classes and enforce a certain structure on derived classes.
Example:
abstract class Shape {
public abstract void Draw();
}
Ques 28. Explain the 'is-a' and 'has-a' relationships in OOP.
'is-a' relationship represents inheritance, where a class is a specialized version of another class. 'has-a' relationship represents composition, where a class contains an instance of another class as a member.
Ques 29. What is the purpose of the 'sealed' keyword in C#?
In C#, the 'sealed' keyword is used to prevent a class from being inherited. It ensures that the class cannot be used as a base class for other classes.
Example:
sealed class MySealedClass {
// class content
}
Ques 30. Explain the term 'covariant return type' in OOP.
Covariant return type allows a method in a subclass to return a more derived type than the method in the base class. It is a feature supported by some programming languages, including C++ and Java.
Most helpful rated by users: