NEW
Font size
WorksheetsC++ OOPs Concepts & Inheritance Quiz
Total questions: 20
Worksheet time: 20mins
Which of the following is not a feature of OOP in C++?
Encapsulation
Abstraction
Inheritance
Compilation
What is the default access specifier for members of a class in C++?
Public
Private
Protected
Internal
What type of inheritance is shown in the following code? class A { }; class B : public A { }; class C : public B { };
Single inheritance
Multiple inheritance
Multilevel inheritance
Hybrid inheritance
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; }
Base class
Derived class
Error
Nothing
Which keyword is used to inherit a class in C++?
inherit
extends
using
:
Which of the following is not a C++ token?
Identifier
Keyword
Punctuation
Class
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; }
Error
10
0
Garbage value
Which of the following is used to resolve ambiguity in multiple inheritance?
this pointer
scope resolution operator (::)
pointer to derived
virtual function
Which inheritance type has a diamond problem in C++?
Single
Multilevel
Multiple
Hierarchical
Which of the following is a correct class declaration in C++?
class MyClass()
class MyClass { };
MyClass class { };
class: MyClass { };
Which of these is not an access specifier in C++?
Public
Protected
Private
Secure
Which operator is used to access members of a class through an object in C++?
::
->
.
#
Which of the following is a token in C++?
Class
+
main()
Return
What will be the output of this code? class A { public: void greet() { cout << "Hello!"; } }; int main() { A obj; obj.greet(); return 0; }
Error
Hello!
Nothing
greet
What is a class in C++?
A built-in function
A template for creating objects
A type of array
An operator
Which of the following best defines encapsulation?
Deriving a class from another class
Binding data and methods together
Hiding implementation details
Reusing code
What is the purpose of inheritance in C++?
To hide data
To reuse existing code
To define tokens
To write header files
Which of the following is a keyword in C++?
void
number
integer
function
Which access specifier allows data to be accessible only within the same class?
Public
Private
Protected
Internal
What is an object in C++?
A function
A variable of class type
A loop structure
A header file
