Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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
✗ Incorrect
The base keyword is used to access members of the base class from within a derived class.
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
✗ Incorrect
You call a base class constructor by using base(parameters) in the derived class constructor's initializer.
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>
✗ Incorrect
You use base.MethodName() to call the base class version of an overridden method.
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
✗ Incorrect
Private fields are not accessible from derived classes, even with base.
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
✗ Incorrect
If you don't call base.Method(), the base method is not executed when the override runs.
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.
Practice
(1/5)
1. What does the base keyword do in C#?
easy
A. It creates a new instance of a class.
B. It allows a child class to access members of its parent class.
C. It defines a new class.
D. It deletes an object from memory.
Solution
Step 1: Understand the role of base
The base keyword is used in a child class to refer to its parent class members.
Step 2: Identify what base allows
It allows access to parent class methods, properties, or constructors from the child class.
Final Answer:
It allows a child class to access members of its parent class. -> Option B
Quick Check:
base keyword = access parent members [OK]
Hint: Remember: base = parent class access [OK]
Common Mistakes:
Confusing base with new instance creation
Thinking base deletes objects
Assuming base defines a class
2. Which of the following is the correct way to call a parent class constructor using base in C#?
easy
A. public Child() : base() { }
B. public Child() base() { }
C. public Child() call base() { }
D. public Child() : parent() { }
Solution
Step 1: Recall syntax for calling parent constructor
In C#, to call a parent constructor, use : base() after the child constructor signature.
Step 2: Match correct syntax
public Child() : base() { } uses public Child() : base() { }, which is the correct syntax.
Final Answer:
public Child() : base() { } -> Option A
Quick Check:
Parent constructor call = : base() [OK]
Hint: Use colon and base() after constructor name [OK]
Common Mistakes:
Omitting colon before base()
Using base() inside constructor body incorrectly
Using wrong keyword like parent()
3. What will be the output of the following code?
class Parent {
public virtual void Show() {
Console.WriteLine("Parent Show");
}
}
class Child : Parent {
public override void Show() {
base.Show();
Console.WriteLine("Child Show");
}
}
var obj = new Child();
obj.Show();
medium
A. Child Show
B. Parent Show
C. Compilation error
D. Parent Show\nChild Show
Solution
Step 1: Understand method overriding and base call
The Child class overrides Show() and calls base.Show() which runs the Parent version first.
Step 2: Trace the output
First, "Parent Show" is printed from base.Show(), then "Child Show" is printed from the child method.
class Parent {
public void Display() {
Console.WriteLine("Parent Display");
}
}
class Child : Parent {
public override void Display() {
base.Display();
Console.WriteLine("Child Display");
}
}
medium
A. Cannot override non-virtual method Display() in Parent.
B. base.Display() is invalid syntax.
C. Child class must not call base.Display().
D. No error, code runs fine.
Solution
Step 1: Check method overriding rules
In C#, only methods marked virtual or abstract in the parent can be overridden.
Step 2: Analyze the Parent class method
The Display() method in Parent is not virtual, so override in Child causes a compile error.
Final Answer:
Cannot override non-virtual method Display() in Parent. -> Option A
Quick Check:
Override requires virtual method [OK]
Hint: Only virtual methods can be overridden [OK]
Common Mistakes:
Trying to override non-virtual method
Confusing base call syntax
Assuming override works without virtual
5. Given the classes below, what will be the output?
class A {
public virtual string GetName() => "A";
}
class B : A {
public override string GetName() => "B";
}
class C : B {
public override string GetName() => base.GetName() + "C";
}
var obj = new C();
Console.WriteLine(obj.GetName());
hard
A. AC
B. Compilation error
C. BC
D. C
Solution
Step 1: Trace method calls through inheritance
Class C overrides GetName() and calls base.GetName(), which refers to B's override returning "B".
Step 2: Combine returned strings
C appends "C" to the result from B, so the final string is "B" + "C" = "BC".
Final Answer:
BC -> Option C
Quick Check:
base.GetName() calls immediate parent method [OK]
Hint: base calls immediate parent method, not grandparent [OK]