CORRECT SOLUTIONS||100%
GUARANTEED PASS||UPDATED
2026/2027 SYLLABUS||<<NEWEST
VERSION>>
How can you specify which constructor to call in a derived classes constructor? -
ANSWER ✓ By appending the child constructor with colon and the specific
parent constructor.
e.g. Child::Child(int x) : Parent(x) {...}
How is multiple inheritance instantiated? - ANSWER ✓ By including more than
one inherited class after the : in the derived class definition.
e.g. class Mustang: public Car, public SportsCar, public Ford
{...
};
What does a friend mean to C++? - ANSWER ✓ A friend is a function that can
use the private and protected members of a class.
However friendship in C++ is one-way. Of course, we all have a friend or two like
that!!!
So if you want it two-way you must declare it. It is also not transitive.
My friends are not your friends, and your friends are not my friends.
usage friend class MyClass;
What is a friend function? - ANSWER ✓ By including the friend keyword
functions external to the class can appear as member functions.
, What are function templates - ANSWER ✓ Generic programming allows for one
class to handle multiple types.
e.g.
tempate <typename T>
T max(T a, T b)
{
if (a>b)
return a;
else
return b;
}
What is a class tempate? - ANSWER ✓ A form of generic declaration of a class.
#include<iostream>
using namespace std;
template <class T> class calc
{
public:
T multiply(T x, T y);
T add(T x, T y);
};
template <class T> T calc<T>::multiply(T x, T y) {
return x*y;
}
template <class T> T calc<T>::add(T x, T y) {
return x+y;
}
int main() {
calc<int> c;
cout << c.add(10,20) << endl;
,}
What kinds of things can you find in the standard template library? - ANSWER ✓
Containers, algorithms and iterators oh my!
What is overloading - ANSWER ✓ It allows you to have more than one definition
for a function or operator in the same scope.
If they have the same name they will have different arguments and
implementations.
Compiler determines appropriate one based on args.
This extends to member functions.
It cannot only differ by return.
Example of << operator overloaded to create a toString style method - ANSWER
✓ friend ostream& operator<<(ostream& os, const Rectangle& rect);
};
ostream& operator<<(ostream& os, const Rectangle& rect) {
os << rect.width << "x" << rect.height;
return os;
}
Can operators be overloaded? - ANSWER ✓ Most of the built-in operators can be
overridden.
For example you can define a concatenation using + for two strings, however the
use of overrides can lead to confusing code if overused or used improperly.
What is polymorphism in C? - ANSWER ✓ In C++, we are usually referring to
sub-type polymorphism, in which we can make use of derived classes through base
class pointers and references
Generally this occurs when a pointer to the parent type is called against a derived
object.
, e.g.
int main() {
Person *p;
Student *s = new Student();
s->sayHello();
p = s;
p->sayHello();
}
How does the virtual keyword affect polymorphism? - ANSWER ✓ It enables
dynamic dispatching.
virtual is expressed in the header and a method declared virtual will stay virtual in
all descendant classes.
virtual should be placed on a parent class function which is expected to be
overridden.
virtual methods can also be left unimplemented, this is called abstract in other
languages.
This forces subclasses to implement.
e.g. virtual void sayHello() = 0;
Can a class containing pure virtual (abstract) methods be instantiated? - ANSWER
✓ No they serve as a base class for other methods.
Derived classes are only instantiatable if all virtual methods are implemented.
Why is the this keyword used? - ANSWER ✓ It is a pointer that refers to the
current object to self reference. It makes code more readable.
What is a static member? - ANSWER ✓ A static member belongs to the class, not
an instance. They do not require instantiation of an object before using.