This quiz on C++ Object-Oriented Programming (OOP) covers topics from basic class and object relationships to advanced concepts like inheritance, polymorphism, and encapsulation, to test your overall understanding of the topic. Each question contains a clear explanation, which will help you understand the correct answers and the underlying principles.
Question 1
Which of the following is not a feature of OOP in C++?
Encapsulation
Inheritance
Polymorphism
Compilation
Question 2
Which OOP concept refers to the ability to create a new class from an existing class?
Encapsulation
Abstraction
Inheritance
Polymorphism
Question 3
Which of the following best describes a constructor in C++?
A function that is called when an object is destroyed
A function that is called when an object is accessed
A function that is called when an object is created
A function that is called when an object is inherited
Question 4
What is the default access specifier for members of a class in C++?
Public
Protected
Private
None
Question 5
What is Encapsulation in C++?
The ability to inherit properties from another class
The ability to overload functions
The ability to create abstract classes
The wrapping of data and methods into a single unit
Question 6
Which OOP principle allows a derived class to override a method in the base class?
Encapsulation
Polymorphism
Abstraction
Inheritance
Question 7
Which of the following type of class allows only one object of it to be created?
Virtual class
Abstract class
Singleton class
Friend class
Question 8
If class A is a friend of class B and class B is a friend of class C, which of the following is true?
Class A is a friend of class C
Class B cannot be a friend of any other class
Class C is a friend of class A
None of the above
Question 9
What will be the output of the below code?
#include<iostream.h>
class Point {
int x, y;
public:
Point(int i = 0, int j = 0) { x = i; y = j; }
int getX() { return x; }
int getY() { return y; }
};
int main() {
Point p1;
Point p2 = p1;
cout << "x = " << p2.getX() << " y = " << p2.getY();
return 0;
}
x = garbage value; y = garbage value
x = 0; y = 0
Compiler Error
Runtime Error
Question 10
Which of the following concepts means determining at runtime what method to invoke?
Data hiding
Dynamic Typing
Dynamic binding
Dynamic loading
There are 23 questions to complete.