Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 15, Problem 1RQE

A class that cannot be instantiated is a(n) _____ .

Expert Solution & Answer
Check Mark
Program Description Answer

The classes which cannot be instantiated are referred as “abstract base class”.

Explanation of Solution

Inheritance:

Inheritance is the concept of inheriting the members and properties of a base class from the derived class. The main advantages of inheritance are,

  • Code reusability and fast implementation.
  • Reduces the program code.

Abstract base class:

Abstract base class is a class which contains at least one pure virtual function.

  • Compiler will not permit the user to instantiate an abstract class.
  • Normally, in function the base class contains the implementation and the derived class overrides this implementation with its own implementation.
  • But, the class which inherits an abstract base class must provide definition to the pure virtual function.
    • The pure virtual functions implementation is not provided, and the function can be made pure virtual by adding (= 0) at the end of the function.
    • The pure virtual function is mostly implemented in the derived class and not in a base class.

Example for abstract base class with virtual function:

/*Abstract base class as it uses virtual function*/

class Base

{

/*Access specifier*/

public:

    /*virtual function*/

    virtual void disp() = 0

};

/*Virtual function definition*/

void Base::disp()     

{

    //statement;

}

Explanation:

In the above example,

  • Define the abstract base class with the name of “Base”.
    • Declare the pure virtual function with the name of “disp()” to make the class as the abstract class.
  • The implementation of pure virtual function “disp()” is not provided in base class. But, it is given outside of the class definition.
  • Hence, the abstract base class “Base” cannot be instantiated.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
__________can be used to assign an object of a class to another object of the same class.
Java:
It is convention that all metmber variables in a Java class are declared to have_____ access so they are not accessible outside the class.

Chapter 15 Solutions

Starting Out with C++: Early Objects (9th Edition)

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
C++ Data Members; Author: CppNuts;https://www.youtube.com/watch?v=StlsYRNnWaE;License: Standard YouTube License, CC-BY