You can prepare effectively for Software Development DSA in C++ with this dedicated MCQ Practice Test (available with solutions) on the important topic of "Test: Object Oriented Programming - 2". These 15 questions have been designed by the experts with the latest curriculum of Software Development 2026, to help you master the concept.
Test Highlights:
Sign up on EduRev for free to attempt this test and track your preparation progress.
Which of the following is not a principle of Object-Oriented Programming (OOP)?
Detailed Solution: Question 1
Which keyword is used to create an object in C++?
Detailed Solution: Question 2
Detailed Solution: Question 3
What is the purpose of a constructor in C++?
Detailed Solution: Question 4
Which access specifier allows the members of a class to be accessible from any other class?
Detailed Solution: Question 5
What will be the output of the following code?
#include <iostream>
class MyClass {
public:
int x;
void display() {
std::cout << "x = " << x << std::endl;
}
};
int main() {
MyClass obj;
obj.x = 5;
obj.display();
return 0;
}
Detailed Solution: Question 6
What will be the output of the following code?
#include <iostream>
class Base {
public:
void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Base* ptr = &d;
ptr->show();
return 0;
}
Detailed Solution: Question 7
What will be the output of the following code?
#include <iostream>
class Base {
public:
virtual void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Base* ptr = &d;
ptr->show();
return 0;
}
Detailed Solution: Question 8
What will be the output of the following code?
#include <iostream>
class Base {
public:
virtual void show() {
std::cout << "Base class" << std::endl;
}
};
class Derived : public Base {
public:
void show() {
std::cout << "Derived class" << std::endl;
}
};
int main() {
Derived d;
Derived* ptr = &d;
Base* bptr = ptr;
bptr->show();
return 0;
}
Detailed Solution: Question 9
What will be the output of the following code?
#include <iostream>
class Base {
public:
int x;
Base() {
x = 0;
}
virtual void display() {
std::cout << "x = " << x << std::endl;
}
};
class Derived : public Base {
public:
Derived() {
x = 5;
}
void display() {
std::cout << "x = " << x << std::endl;
}
};
int main() {
Base* bptr = new Derived();
bptr->display();
delete bptr;
return 0;
}
Detailed Solution: Question 10
Which type of inheritance is illustrated in the following code?
class A {
public:
void foo() {
std::cout << "A" << std::endl;
}
};
class B : public A {
public:
void foo() {
std::cout << "B" << std::endl;
}
};
int main() {
B b;
b.foo();
return 0;
}
Detailed Solution: Question 11
Which statement is true about function overriding in C++?
Detailed Solution: Question 12
What is the output of the following code?
#include <iostream>
class A {
public:
virtual void foo() {
std::cout << "A" << std::endl;
}
};
class B : public A {
public:
void foo() {
std::cout << "B" << std::endl;
}
};
int main() {
A* ptr = new B();
B* bptr = dynamic_cast<B*>(ptr);
bptr->foo();
return 0;
}
Detailed Solution: Question 13
Which statement is true about pure virtual functions in C++?
Detailed Solution: Question 14
Which concept is illustrated in the following code?
class Base {
public:
virtual void foo() = 0;
};
class Derived : public Base {
public:
void foo() {
std::cout << "Derived" << std::endl;
}
};
int main() {
Base* ptr = new Derived();
ptr->foo();
return 0;
}
Detailed Solution: Question 15
152 videos|118 docs|24 tests |