wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C++ OOPs Concepts & Inheritance Quiz

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Which of the following is not a feature of OOP in C++?

a)

Encapsulation

b)

Abstraction

c)

Inheritance

d)

Compilation

2.

What is the default access specifier for members of a class in C++?

a)

Public

b)

Private

c)

Protected

d)

Internal

3.

What type of inheritance is shown in the following code? class A { }; class B : public A { }; class C : public B { };

a)

Single inheritance

b)

Multiple inheritance

c)

Multilevel inheritance

d)

Hybrid inheritance

4.

What is the output of this code? class Base { public: void show() { cout << "Base class"; } }; class Derived : public Base { public: void show() { cout << "Derived class"; } }; int main() { Derived d; d.show(); return 0; }

a)

Base class

b)

Derived class

c)

Error

d)

Nothing

5.

Which keyword is used to inherit a class in C++?

a)

inherit

b)

extends

c)

using

d)

:

6.

Which of the following is not a C++ token?

a)

Identifier

b)

Keyword

c)

Punctuation

d)

Class

7.

What is the output of this code snippet? class A { public: int x = 10; }; class B : public A { public: void display() { cout << x; } }; int main() { B obj; obj.display(); return 0; }

a)

Error

b)

10

c)

0

d)

Garbage value

8.

Which of the following is used to resolve ambiguity in multiple inheritance?

a)

this pointer

b)

scope resolution operator (::)

c)

pointer to derived

d)

virtual function

9.

Which inheritance type has a diamond problem in C++?

a)

Single

b)

Multilevel

c)

Multiple

d)

Hierarchical

10.

Which of the following is a correct class declaration in C++?

a)

class MyClass()

b)

class MyClass { };

c)

MyClass class { };

d)

class: MyClass { };

11.

Which of these is not an access specifier in C++?

a)

Public

b)

Protected

c)

Private

d)

Secure

12.

Which operator is used to access members of a class through an object in C++?

a)

::

b)

->

c)

.

d)

#

13.

Which of the following is a token in C++?

a)

Class

b)

+

c)

main()

d)

Return

14.

What will be the output of this code? class A { public: void greet() { cout << "Hello!"; } }; int main() { A obj; obj.greet(); return 0; }

a)

Error

b)

Hello!

c)

Nothing

d)

greet

15.

What is a class in C++?

a)

A built-in function

b)

A template for creating objects

c)

A type of array

d)

An operator

16.

Which of the following best defines encapsulation?

a)

Deriving a class from another class

b)

Binding data and methods together

c)

Hiding implementation details

d)

Reusing code

17.

What is the purpose of inheritance in C++?

a)

To hide data

b)

To reuse existing code

c)

To define tokens

d)

To write header files

18.

Which of the following is a keyword in C++?

a)

void

b)

number

c)

integer

d)

function

19.

Which access specifier allows data to be accessible only within the same class?

a)

Public

b)

Private

c)

Protected

d)

Internal

20.

What is an object in C++?

a)

A function

b)

A variable of class type

c)

A loop structure

d)

A header file