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

Base keyword behavior in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the base keyword do in C#?
The <code>base</code> keyword lets a derived class access members (methods, properties, constructors) of its base class. It helps call or refer to the base class version of a member.
Click to reveal answer
beginner
How do you use <code>base</code> to call a base class constructor?
You use <code>base(arguments)</code> in the derived class constructor's initializer to call a specific base class constructor before running the derived constructor's body.
Click to reveal answer
intermediate
Can base be used to access overridden methods?
Yes. Inside an overridden method, <code>base.MethodName()</code> calls the base class version of that method, bypassing the override.
Click to reveal answer
beginner
What happens if you don't use base when overriding a method?
If you don't use <code>base</code>, the derived class method completely replaces the base class method. The base method is not called unless explicitly invoked with <code>base</code>.
Click to reveal answer
intermediate
Can <code>base</code> be used to access base class fields directly?
No. <code>base</code> cannot be used to access base class fields directly if they are private. It works with accessible members like protected or public fields, properties, and methods.
Click to reveal answer
What is the purpose of the base keyword in C#?
ATo access members of the base class from a derived class
BTo create a new instance of a class
CTo declare a new class
DTo override a method
How do you call a base class constructor with parameters from a derived class?
AUsing <code>this(parameters)</code> in the derived constructor
BUsing <code>base(parameters)</code> in the derived constructor initializer
CBy calling <code>new BaseClass(parameters)</code> inside the derived constructor
DYou cannot call base class constructors explicitly
Inside an overridden method, how do you call the base class version of that method?
AUsing <code>super.MethodName()</code>
BUsing <code>this.MethodName()</code>
CYou cannot call the base method once overridden
DUsing <code>base.MethodName()</code>
Can base be used to access private fields of the base class?
AOnly if the derived class is in the same namespace
BYes, always
CNo, private fields are not accessible even with <code>base</code>
DOnly if the field is static
What happens if you override a method but do not call base.Method() inside it?
AThe base method is not executed
BThe base method is automatically called
CThe program will not compile
DThe base method is called twice
Explain how the base keyword helps when overriding methods in C#.
Think about how to run the original method from the base class when you have a new version in the derived class.
You got /3 concepts.
    Describe how to use base to call a base class constructor from a derived class constructor.
    Remember the syntax after the colon in the derived constructor.
    You got /3 concepts.