CARVIEW |
C# - Inheritance and Polymorphism Quiz
Question 1
Which of the following statements about inheritance in C# is correct?
A subclass can inherit from multiple classes directly.
A subclass can inherit private members of the superclass directly.
A subclass can inherit from only one class but multiple interfaces.
A base class cannot have more than one derived class.
Question 2
In multilevel inheritance, if class C inherits from class B and class B inherits from class A, which class is the base class for class C?
Only class A
Only class B
Both class A and B
None of the above
Question 3
In C#, if no superclass is specified, a class implicitly inherits from:
System.Object
System.Base
System.Class
None of the above
Question 4
For a method in a derived class to override a method in the base class, which keywords are required?
virtual in base class and override in derived class
abstract in base class and override in derived class
Only override in derived class
Only virtual in base class
Question 5
What happens if a derived class defines a method with the same name as the base class method but the base method is not marked as virtual?
It results in a compile-time error.
It automatically overrides the base method.
It hides the base method instead of overriding it.
It throws an exception at runtime.
Question 6
What is the purpose of the base keyword in C#?
To create a new instance of the base class.
To access private members of the base class.
To call base class methods/constructors from derived classes.
To prevent method overriding.
Question 7
Which of the following best describes polymorphism in C#?
A feature that allows a class to have multiple constructors.
A feature that allows methods or operators to take multiple forms.
A feature that allows a class to implement multiple interfaces.
A feature that allows automatic memory management.
Question 8
Which technique is used to achieve compile-time polymorphism in C#?
Method Overriding
Method Overloading
Virtual Methods
Abstract Classes
Question 9
Which of the following is an example of runtime polymorphism in C#?
Method Overloading
Operator Overloading
Method Overriding using virtual and override
Constructor Overloading
Question 10
What does operator overloading in C# allow?
Creating new operators in C#
Redefining how existing operators work with user-defined types
Overriding operators like + in base classes only
Replacing all built-in operators with custom logic
There are 10 questions to complete.