C Sharp Inheritance Questions and Answers

Practice Mode
Showing 10 of 29 questions
Q21
What is the purpose of the "new" keyword when used with inheritance?
  • A To override a base method
  • B To hide a base method
  • C To create a new instance
  • D To call base class method
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?
  • A Sealed class
  • B Static class
  • C Abstract class
  • D Any class
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?
  • A Multiple methods with same name
  • B Ability to take many forms
  • C Hiding implementation details
  • D Creating multiple classes
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#?
  • A Main()
  • B Constructor
  • C Destructor
  • D Initialize()
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#?
  • A public
  • B private
  • C internal
  • D protected
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?
  • A Single inheritance
  • B Multiple inheritance
  • C Multilevel inheritance
  • D Hierarchical inheritance
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?
  • A Call base class constructor
  • B Refer to current instance
  • C Create new object
  • D Call static methods
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?
  • A Polymorphism
  • B Encapsulation
  • C Diamond problem
  • D Abstraction
Answer: Option C
Explanation: Diamond problem occurs when a class inherits from multiple classes with common ancestry.
Q29
What is method overriding in inheritance?
  • A Creating new method with same name
  • B Hiding base class method
  • C Providing specific implementation in derived class
  • D Making method private
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.
Questions and Answers for Competitive Exams Various Entrance Test