A class that cannot be instantiated is a(n) _____ .
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?
Chapter 15 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Degarmo's Materials And Processes In Manufacturing
Web Development and Design Foundations with HTML5 (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
SURVEY OF OPERATING SYSTEMS
Management Information Systems: Managing The Digital Firm (16th Edition)
- C++ Language Activity 5: DERIVED CLASS • Create a SAVING ACCOUNT class that inherits the class BANK ACCOUNT. • Create a constructor for the derived class that accepts INTEREST RATE. • Create a method that displays the INTEREST RATE. • Create a method that computes the INTEREST (BALANCE * INTEREST RATE) and adds to the current BALANCE.arrow_forwardPython Programming A- Define a class called Vehicle as follows: The Vehicle class has two instance variables: name, max_speed Define an __init__ function for the Vehicle class that initializes the name and max_speed instance variables Define get and set methods for each of the name and max_speed variables. You may call them getName, getMax_speed, setName and setMax_speed Define a __str__ function that prints the name and max_speed of the Vehicle class. B- Define a class called Car as follows: The Car class is a subclass of the Vehicle class. The Car class has an instance variable called number_of_cylinders Define an __init__ function for the Car class that initializes the name and max_speed and number_of_cylinders instance variables Please note that the Car class inherits the name and max_speed variables from the Vehicle class and does not redefine them. Define get and set methods for the number_of_cylinders variable. Define a __str__ function that prints the name and…arrow_forwardExercises abstract class • Design a new Triangle class that extends the abstract GeometricObject class: • Draw the UML diagram for the classes Triangle and GeometricObject • Implement the Triangle class • Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled: • The program should create a Triangle object with these sides and set the color and filled properties using the input • The program should display the area, perimeter, color, and true or false to indicate whether it is filled or notarrow_forward
- #pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardT/F A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.arrow_forwardEmployee class Write a Python program employee.py that computes the cumulative salary of employees based on the length of their contract and their annual merit rate. Your program must include a class Employee with the following requirements: Class attributes: name: the name of the employee position: the position of the employee start_salary: the starting salary of the employee annual_rate: the annual merit rate on the salary contract_years: the number of years of salary Class method: get_cumulative_salary(): calculates and returns the cumulative salary of an employee based on the number of contract years. Round the cumulative salary to two digits after the decimal point. Example: If start_salary = 100000, annual_rate = 5% and contract_years = 3: Then the cumulative salary should be : 100000 + 105000 + 110250 = 315250 Outside of the class Employee, the program should have two functions: Function name Function description Function input(s) Function output(s) / return…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning