0
0
C Sharp (C#)programming~5 mins

Base class and derived class in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a base class in C#?
A base class is a class that provides common properties and methods which other classes (derived classes) can inherit and reuse.
Click to reveal answer
beginner
What does it mean for a class to be derived from a base class?
A derived class inherits members (properties and methods) from the base class and can add its own members or override existing ones.
Click to reveal answer
beginner
How do you declare a derived class in C#?
Use a colon (:) after the class name followed by the base class name. Example: <code>class Dog : Animal { }</code>
Click to reveal answer
intermediate
Can a derived class access private members of its base class?
No, private members of a base class are not accessible directly by derived classes. They can access protected or public members.
Click to reveal answer
intermediate
What is method overriding in the context of base and derived classes?
Method overriding allows a derived class to provide a new implementation of a method defined in the base class using the <code>override</code> keyword.
Click to reveal answer
Which keyword is used to inherit from a base class in C#?
Ainherits
Bextends
C:
Dimplements
If class B derives from class A, which members can B access directly?
AOnly private members of A
BAll members including private of A
COnly public members of A
DPublic and protected members of A
What keyword must be used in the base class method to allow overriding?
Aabstract
Bvirtual
Cnew
Doverride
Which keyword is used in the derived class to override a base class method?
Aoverride
Bvirtual
Cnew
Dbase
What happens if a derived class does not override a virtual method?
AThe base class version is used
BCompilation error occurs
CThe method is hidden
DThe method is deleted
Explain how inheritance works between a base class and a derived class in C#.
Think about how a child inherits traits from a parent.
You got /3 concepts.
    Describe the difference between private, protected, and public members in the context of base and derived classes.
    Consider who can see or use each member.
    You got /3 concepts.