📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      In C++, how is abstraction primarily achieved when

      defining a class that cannot be instantiated directly but serves as a blueprint for derived classes?
      A By making all member variables `private`. Correct Answer Incorrect Answer
      B By using the `virtual` keyword for all methods. Correct Answer Incorrect Answer
      C By declaring at least one pure virtual function (e.g., `virtual void func() = 0;`). Correct Answer Incorrect Answer
      D By making the constructor `protected`. Correct Answer Incorrect Answer
      E By using the `abstract` keyword (which does not exist in C++). Correct Answer Incorrect Answer

      Solution

      o In C++, a class is considered an abstract base class if it has at least one pure virtual function. A pure virtual function is declared by assigning = 0 to it in the base class's declaration (e.g., virtual void func() = 0;). o Abstract classes cannot be instantiated directly. They serve as interfaces or blueprints, forcing derived classes to provide implementations for all pure virtual functions to become concrete (instantiable).

      Practice Next
      More IT Operating System Questions
      ask-question