Inheritance in C++ - Reading Assignment


#81

Article 11.1

1. why do we need inheritance in C++?
inheritance is in everything in the real world just like in the programming world. Different programming languages inherit different properties front earlier programming languages. inheritance involves creating new objects by directly acquiring the attributes and behaviors of other objects and than extending them or specializing them.
2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance.
An oak tree and a pine tree have both inherited the tree properties.

Article 11.2

1. What is a superclass and what is a subclass?
The class being inherited from is a super class and the class doing the inhereiting is the sub class.

2. How would you write a public inheritance in C++?
class baseballplayer : public person
{jhsddbkas
};

3. In what ways can a subclass extend the functionality of a superclass?
By inheriting from a base class, which allows us to use the information already assigned to that clas and apply it to the derived classes.


#82

Part 1

Why do we need inheritance in C++?

  • Inheriting from a base class means we don’t have to redefine the information from the base class in our derived classes.
  • We automatically receive the member functions and member variables of the base class through inheritance, and then simply add the additional functions or member variables we want.
  • This not only saves work, but also means that if we ever update or modify the base class, all of our derived classes will automatically inherit the changes.

Give a simple example of objects in the real world that could be modelled in C++ using inheritance.

  • Banana and Apples inherit from Fruit

Part 2

What is a superclass and what is a subclass?

  • A superclass (also called parent class or base class) is the class being inherited from.
  • A subclass (also called the child class or derived class) is the class doing the inheriting.

How would you write a public inheritance in C++?

  • After the class name write a colon and the word public and the name of the class we wish to inherit.
  • e.g. class BaseballPlayer : public Person

In what ways can a subclass extend the functionality of a superclass?

  • A subclass inherits all the variables and methods from a superclass and adds their own methods and variables thus extending the functionality of a superclass.

#83

Part 1:

  1. Why do we need inheritance in C++?

    Inheritance allow the creation of complex objects by using all the features of an exhisting objext, but with the ability to add additional, specialized features.

  2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance.

    Cars - most features of previous models are included in the new versions.

Part 2:

  1. What is a superclass and what is a subclass?

    The class being inherited from is called the superclass, and the class doing the inheriting is called the subclass.

  2. How would you write a public inheritance in C++?

    class SubClass : public SuperClass

  3. In what ways can a subclass extend the functionality of a superclass?

    Inheriting from a superclass saves work by only requiring the addition of additional functions needed instead of rewriting the entire class. In addition, any updates to the superclass will automatically be inherited by the subclasses.


#84

PART 1

1. Why do we need inheritance in C++?
Inheritance is important because it is an efficient way of creating new objects that acquire attributes and behaviors from a more general and encompassing object. With inheritance, we don’t need to repeat code that has already been written to define these attributes and behaviors. New objects simply inherit them, and they can have their own more specialized attributes and behaviors.

2. Give a simple example of objects in the real world that could be modeled in C++ using inheritance.

Orchestral Musical Instruments (top-most object)
String Instruments | Percussions | Winds | Metals
Under Strings: Violin, Viola, Cellos, Bass
Under Percussions: Piano, Xylophone, Cymbals, Drums, etc.
Under Winds: Flute, Oboe, Clarinet, French Horn, Bassoon
Under Metals: Trumpet, Trombone, Tuba

PART 2

1. What is a superclass and what is a subclass?
A superclass (also known as parent class or base class) is the class from which other other classes will inherit attributes (properties) and behaviors (functions) from.
A subclass (also known as child class, derived class, or subclass) is the one that inherits the attributes and behaviors from the superclass.

2. How would you write a public inheritance in C++?

class StringInstrument : public OrchestralInstrument

3. In what ways can a subclass extend the functionality of a superclass?
The subclass adds specialized properties (member variables) and behaviors (member functions) that don’t have to be determined when first creating the superclass. This is efficient because programmers don’t have to think of every possible property or behavior or child classes beforehand.


#85
  1. It allows classes to be created more simply by building on attribute of parent classes

  2. A sport car is a type of car, a car is a type of vehicle.

  3. A super class is the parent or base class that give its attributes a subclass or or child class.

  4. We write the key word class followed by the name of the child class followed by : followed by the key word public and finally the name of the parent class

  5. The child class automatically inherits the variables and methods of the parent class.