0
0
C++programming~5 mins

Base and derived classes in 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 properties and behaviors (methods) which can be inherited by other classes called derived classes.
Click to reveal answer
beginner
What is a derived class?
A derived class is a class that inherits properties and behaviors from a base class and can add its own features or modify existing ones.
Click to reveal answer
beginner
How do you declare a derived class from a base class in C++?
Use the syntax: <br> <code>class DerivedClass : access_specifier BaseClass { ... };</code> <br> where <code>access_specifier</code> is usually <code>public</code>.
Click to reveal answer
intermediate
What happens if a derived class does not define a constructor?
The derived class automatically calls the base class's default constructor to initialize the base part of the object.
Click to reveal answer
intermediate
Can a derived class access private members of its base class directly?
No, private members of a base class are not accessible directly by derived classes. They can be accessed through public or protected methods of the base class.
Click to reveal answer
Which keyword is used to inherit a class in C++?
Aextends
Binherit
Cclass
D:
If class B inherits publicly from class A, which members of A are accessible in B?
Aprivate members only
Ball members
Cpublic and protected members
Dnone
What is the default access specifier for inheritance in C++ classes?
Aprivate
Bnone
Cprotected
Dpublic
Which of these is true about constructors in derived classes?
ADerived class constructors must call base class constructors explicitly.
BBase class default constructor is called automatically if not specified.
CDerived class constructors do not call base class constructors.
DDerived class cannot have constructors.
Can a derived class override a base class method?
AYes, if the base method is virtual.
BNo, methods cannot be overridden.
COnly if the method is private.
DOnly if the method is static.
Explain how inheritance works between a base class and a derived class in C++.
Think about how the derived class gets features from the base class.
You got /5 concepts.
    Describe the role of constructors in base and derived classes during object creation.
    Consider which constructor runs first and how the base part is initialized.
    You got /5 concepts.