Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Mastering C++ OOP Concepts

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the main principle of Object-Oriented Programming?

a)

Encapsulation of data and behavior into objects.

b)

Static typing of all variables in the program.

c)

Polymorphism through method overloading only.

d)

Inheritance of properties from a parent class.

2.

Define encapsulation in the context of C++.

a)

Encapsulation is the bundling of data and methods that operate on that data, restricting direct access to some of the object's components.

b)

Encapsulation is the method of optimizing code performance in C++.

c)

Encapsulation refers to the inheritance of properties from a parent class.

d)

Encapsulation is the process of creating multiple instances of a class.

3.

What is the purpose of a constructor in a C++ class?

a)

To define the class structure.

b)

The purpose of a constructor in a C++ class is to initialize objects.

c)

To delete objects from memory.

d)

To create a copy of an object.

4.

Explain the concept of inheritance in C++.

a)

Inheritance allows a base class to inherit attributes from a derived class.

b)

Inheritance is a method to create new classes without any relationship to existing classes.

c)

Inheritance in C++ is used to delete classes and their methods.

d)

Inheritance allows a derived class to inherit attributes and methods from a base class, promoting code reusability and establishing class hierarchies.

5.

What is polymorphism and how is it implemented in C++?

a)

Polymorphism in C++ allows for multiple inheritance without any common interface.

b)

Polymorphism is only achieved through operator overloading in C++.

c)

Polymorphism refers to the ability to create multiple instances of a class without any interfaces.

d)

Polymorphism in C++ is the ability for different classes to be treated as instances of the same class through a common interface, implemented via function overriding and virtual functions.

6.

Differentiate between class and struct in C++.

a)

Structs support inheritance, while classes do not.

b)

Classes are used for procedural programming, while structs are used for object-oriented programming.

c)

Classes default to private access, while structs default to public access.

d)

Classes can only contain methods, while structs can only contain data members.

7.

What is an abstract class in C++?

a)

An abstract class is a class that can be fully instantiated.

b)

An abstract class can be instantiated if it has no virtual functions.

c)

An abstract class in C++ is a class that cannot be instantiated and contains at least one pure virtual function.

d)

An abstract class must contain only static methods.

8.

How do you achieve method overriding in C++?

a)

Use the 'virtual' keyword in the base class and redefine the function in the derived class.

b)

Redefine the function in the base class only.

c)

Use the 'final' keyword in the derived class.

d)

Use the 'override' keyword in the base class.

9.

What is the significance of the 'virtual' keyword in C++?

a)

The 'virtual' keyword allows methods to be overridden in derived classes, enabling polymorphism.

b)

The 'virtual' keyword is only applicable to global functions in C++.

c)

The 'virtual' keyword prevents method overriding in derived classes.

d)

The 'virtual' keyword is used to declare static methods in C++.

10.

Explain the concept of multiple inheritance in C++.

a)

Multiple inheritance is a feature that allows a class to inherit from multiple derived classes.

b)

Multiple inheritance allows a class to inherit from a single base class.

c)

Multiple inheritance in C++ is a feature that allows a class to inherit from multiple base classes.

d)

Multiple inheritance is not supported in C++.