Abstraction Interview Questions

    Question 1C++ OOPS Abstraction Concept

    What is the main purpose of abstraction in C++?

    Question 2C++ OOPS Abstract Class

    Which keyword is used to declare a pure virtual function in C++?

    Question 3C++ OOPS Interface through Abstract Class

    How can abstraction be achieved in C++?

    Question 4C++ OOPS Pure Virtual Function Example

    What will be the output of the following code?

    #include <iostream> using namespace std; class Shape { public: virtual void draw() = 0; }; class Circle : public Shape { public: void draw() { cout << "Drawing Circle"; } }; int main() { Circle c; c.draw(); }

    Question 5C++ OOPS Abstract Class Instantiation

    What happens if you try to instantiate an abstract class in C++?

    Question 6C++ OOPS Abstraction with Multiple Derived Classes

    What will be the output of this code?

    #include <iostream> using namespace std; class Animal { public: virtual void sound() = 0; }; class Dog : public Animal { public: void sound() { cout << "Bark"; } }; class Cat : public Animal { public: void sound() { cout << "Meow"; } }; int main() { Animal* a = new Dog(); a->sound(); }

    Question 7C++ OOPS Partial Abstraction

    Can an abstract class in C++ have normal (non-virtual) functions?

    Question 8C++ OOPS Pure Virtual Function Without Definition

    Which of the following is true about pure virtual functions?

    Question 9C++ OOPS Abstract Class Pointer

    What will be the output?

    #include <iostream> using namespace std; class Base { public: virtual void show() = 0; }; class Derived : public Base { public: void show() { cout << "Derived"; } }; int main() { Base* b = new Derived(); b->show(); }

    Question 10C++ OOPS Real-life Example of Abstraction

    Which is the best real-life example of abstraction in C++?