C Sharp Inheritance Questions and Answers

Practice Mode
Showing 10 of 29 questions
Q11
What keyword is used to implement inheritance in C#?
  • A extends
  • B inherits
  • C implements
  • D colon (:)
Answer: Option D
Explanation: The colon (:) symbol is used to implement inheritance between classes in C#.
Q12
Which class cannot be inherited in C#?
  • A Abstract class
  • B Sealed class
  • C Static class
  • D Partial class
Answer: Option B
Explanation: Sealed classes are designed to prevent inheritance in C#.
Q13
What is the root class of all classes in C#?
  • A System
  • B Base
  • C Object
  • D Root
Answer: Option C
Explanation: Object class is the ultimate base class for all classes in the .NET Framework.
Q14
Which access modifier allows a member to be accessible only within its own class and derived classes?
  • A private
  • B public
  • C internal
  • D protected
Answer: Option D
Explanation: Protected members are accessible within the class and by derived class instances.
Q15
What keyword is used to call the base class constructor from a derived class?
  • A super
  • B this
  • C base
  • D parent
Answer: Option C
Explanation: The base keyword is used to call base class constructors and methods.
Q16
Which of the following is true about abstract classes?
  • A They can be instantiated
  • B They cannot have abstract methods
  • C They cannot be inherited
  • D They must be inherited to be used
Answer: Option D
Explanation: Abstract classes cannot be instantiated and must be inherited.
Q17
What is the main purpose of the "virtual" keyword in C#?
  • A To make method static
  • B To prevent method overriding
  • C To allow method overriding
  • D To make method private
Answer: Option C
Explanation: Virtual keyword allows methods to be overridden in derived classes.
Q18
Which keyword is used to override a method in a derived class?
  • A overrides
  • B new
  • C override
  • D virtual
Answer: Option C
Explanation: Override keyword explicitly indicates that a method is intended to override a base class method.
Q19
What happens if a class does not explicitly inherit from any class?
  • A It becomes a sealed class
  • B It inherits from Object class
  • C It causes compilation error
  • D It becomes an abstract class
Answer: Option B
Explanation: In C#, all classes implicitly inherit from Object class if no explicit inheritance is specified.
Q20
Which of the following can implement multiple inheritance in C#?
  • A Abstract classes
  • B Sealed classes
  • C Interfaces
  • D Static classes
Answer: Option C
Explanation: Interfaces allow a class to implement multiple inheritance in C#.
Questions and Answers for Competitive Exams Various Entrance Test