Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C++ Quiz 1

Total questions: 30

Worksheet time: 10mins

Name
Class
Date
1.

The scope resolution operator (::) is mainly used in C++ to:

a)

Resolve naming conflicts involving inherited members

b)

Access private class members directly

c)

Define preprocessor-level macros

d)

Implement operator overloading

2.

The inheritance model that allows a derived class to obtain features from more than one base class is:

a)

Single

b)

Multiple

c)

Multilevel

d)

Hierarchical

3.

Ambiguity caused by multiple inheritance (such as identical function names in base classes) is typically resolved using:

a)

this pointer

b)

Scope resolution operator (::)

c)

friend functions

d)

templates

4.

An abstract class is correctly defined as one that:

a)

Cannot be inherited further

b)

Contains no executable member functions

c)

Contains at least one pure virtual function

d)

Cannot hold data members

5.

A tree-structured inheritance model, where several classes derive from a single base, is known as:

a)

Single

b)

Hierarchical

c)

Hybrid

d)

Multilevel

6.

When creating an object of a derived class, the first constructor that executes is the:

a)

Derived class constructor

b)

Base class constructor

c)

Destructor

d)

None

7.

Which of the following holds true regarding constructors in inheritance?

a)

Derived class must manually call the base constructor

b)

Base class constructor is invoked automatically

c)

Constructors can be inherited directly

d)

All constructors are virtual

8.

The diamond problem occurs primarily in:

a)

Multilevel inheritance

b)

Hierarchical inheritance

c)

Multiple inheritance

d)

Single inheritance

9.

An inheritance system combining two or more types of inheritance structures is known as:

a)

Hybrid inheritance

b)

Multiple inheritance

c)

Multilevel inheritance

d)

Hierarchical inheritance

10.

Inheritance enhances which programming principles?

a)

Encapsulation only

b)

Reusability only

c)

Both encapsulation and reusability

d)

None of the above

11.

An access specifier that permits derived classes to use base class members but restricts access outside the hierarchy is:

a)

Private

b)

Protected

c)

Public

d)

Default

12.

If no access mode is specified during inheritance, the default mode for classes is:

a)

Public

b)

Private

c)

Protected

d)

Virtual

13.

Ambiguity arising in multiple inheritance can be avoided by using:

a)

Virtual base class

b)

Inline functions

c)

Operator overloading

d)

Static members

14.

Abstract classes are permitted to:

a)

Be instantiated directly

b)

Contain pure virtual functions

c)

Avoid defining any functions

d)

Block inheritance

15.

To transform a derived class from abstract to concrete, it must override the:

a)

Virtual destructor

b)

Pure virtual function(s)

c)

Constructor

d)

Friend function

16.

In inheritance, constructors of derived classes execute:

a)

Before base constructors

b)

After base constructors

c)

In arbitrary order

d)

Only when explicitly called

17.

Destructors in an inheritance chain run in which order?

a)

Base first, then derived

b)

Derived first, then base

c)

Both simultaneously

d)

Destructors cannot be inherited

18.

To ensure correct destruction when working with pointers to base classes, destructors should be declared as:

a)

const

b)

virtual

c)

protected

d)

static

19.

If a derived class declares no constructor, then upon object creation:

a)

Object creation is impossible

b)

Base class constructor still runs automatically

c)

Compilation fails

d)

Destructor executes instead

20.

Without using virtual base classes, which inheritance model most commonly produces ambiguity?

a)

Single

b)

Multiple

c)

Hybrid

d)

Hierarchical

21.

Which of the following correctly defines a pure virtual function?

a)

virtual void show() = 0;

b)

void show() = 0;

c)

pure virtual void show();

d)

abstract void show();

22.

Ambiguity in inheritance typically arises when:

a)

Two base classes define identically named functions

b)

Only single inheritance is used

c)

A function is overloaded

d)

Virtual destructors are present

23.

Which of the following is not a valid inheritance form supported by C++?

a)

Single

b)

Multiple

c)

Multilevel

d)

Sequential

24.

If both base and derived classes define constructors, the constructor that runs first is from:

a)

Derived

b)

Base

c)

Both simultaneously

d)

Compiler-dependent

25.

Inheritance is often referred to as a mechanism for:

a)

Encapsulation

b)

Specialization

c)

Polymorphism

d)

Abstraction

26.

Which of the following members can be inherited and accessed by derived classes?

a)

Constructors

b)

Private data members

c)

Public member functions

d)

Destructors

27.

A student who inherits from both Person and Athlete classes exhibits which type of inheritance?

a)

Single

b)

Multiple

c)

Hierarchical

d)

Multilevel

28.

When two base classes contain parameterized constructors, the derived class must:

a)

Rely on automatic compiler invocation

b)

Invoke both constructors explicitly in its initializer list

c)

Ignore those constructors

d)

Allow the compiler to choose one randomly

29.

Method overriding in inheritance refers to:

a)

Redefining a base class method inside the derived class

b)

Using friend functions across classes

c)

Implementing operator overloading

d)

None of these

30.

If Class C inherits from B, and B inherits from A, this illustrates:

a)

Single

b)

Multiple

c)

Multilevel

d)

Hybrid