C Sharp Inheritance Questions and Answers
Practice ModeShowing 10 of 29 questions
Q21
What is the purpose of the "new" keyword when used with inheritance?
Answer: Option B
Explanation: The new keyword hides a method from the base class rather than overriding it.
Q22
Which type of class can have abstract methods?
Answer: Option C
Explanation: Only abstract classes can contain abstract methods that must be implemented by derived classes.
Q23
What is polymorphism in the context of inheritance?
Answer: Option B
Explanation: Polymorphism allows methods to behave differently based on the object type at runtime.
Q24
Which method is called when an object is created in C#?
Answer: Option B
Explanation: Constructors are special methods called automatically when objects are instantiated.
Q25
What is the default access modifier for class members in C#?
Answer: Option B
Explanation: In C#, class members have private access by default if no access modifier is specified.
Q26
Which inheritance type allows a class to inherit from multiple interfaces?
Answer: Option B
Explanation: C# supports multiple interface inheritance where a class can implement multiple interfaces.
Q27
What is the purpose of the "this" keyword in inheritance?
Answer: Option B
Explanation: The this keyword refers to the current instance of the class and can be used to access current class members.
Q28
Which concept allows a derived class to have multiple base classes through different paths?
Answer: Option C
Explanation: Diamond problem occurs when a class inherits from multiple classes with common ancestry.
Q29
What is method overriding in inheritance?
Answer: Option C
Explanation: Method overriding allows a derived class to provide a specific implementation of a method that is already defined in its base class.