Inheritance in C++ - Reading Assignment

PART 1

  1. Why do we need inheritance in C++?
    To have objects inherit properties of other objects so that things don’t need to be redefined.
  2. Give a simple example of objects in the real world that could be modeled in C++ using inheritance.
    Fruit-> Apple/orange

PART 2

  1. What is a superclass and what is a subclass?
    The class being inherited from is the superclass and the class inheriting properties is a 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?
    It inherits its functions and variables. So a “baseball player” class that inherits “person” class functionality can do things such as getName() from the person class.
1 Like
  1. Why do we need inheritance in C++?
    Inheritance involves creating new objects by directly acquiring the attributes and behaviors of other objects and then extending or specializing them.

  2. Give a simple example of objects in the real world that could be modeled in C++ using inheritance.
    Apple and banana are both inheritances of a fruit.

  3. What is a superclass and what is a subclass?
    The class being inherited from is called the parent class or superclass, and the class doing the inheriting is called the child class or subclass.

  4. How would you write a public inheritance in C++?
    class BaseballPlayer : public Person
    {
    // …
    };

  5. In what ways can a subclass extend the functionality of a superclass?
    We can add new methods and also variables specifically to a subclass.

1 Like
  1. So we can use certain functionality from other classes without actually retyping them each time

  2. Mammals --> Primates --> Homo Sapiens --> European --> French --> Individual

==============================================================================

  1. A superclass is a more general class that subclasses inherit from

  2. class Country : public People {

    };

  3. All the functionality from a superclass are inherited, but new functionality is added in the subclass

1 Like
  1. We need inheritance in C++ , because when certain objects or classes come from already existing ones we can add more flexibility and also have a better understanding of the code as a whole . This could also help with fixing errors.

  2. We can have a company class and the members can be different people with their properties also as classes. Different example can be a family class and by inheritance we can add the family members.

  1. The superclass is the head class from which all of the relations, information , and inheritance begins.
    The subclass is the class based on the superclass and created by inheritance.

  2. First we write the class name and then we write the word ‘public’ , next to which we write the name of the class we want to inherit from.

  3. The subclass takes all of the superclass’ members and functionalities and adds to it its own features without changing the superclass.

1 Like

Why do we need inheritance in C++?
It is a ways to inherit the properties to objects. Which means each object has the same basic proberties. ( As example, we have different taste of beers, but they are all beers right :slight_smile: )

Give a simple example of objects in the real world that could be modelled in C++ using inheritance.
Different coloursshapes. As example : grey ==> darkgrey ==> lightgrey…

What is a superclass and what is a subclass?
A superclass gives some of the properties to a sub class .

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

class earth : public planets{
 ....
};

In what ways can a subclass extend the functionality of a superclass?
A subclass cann add new variables and methods to the inherited properties.
And this can also be changing/overwriting the existing ones

1 Like

1.) to easily and quickly copy existing Objects
2.) hand tools are a sub class of tools

1.) The class being inherited from is called superclass
The class doing the inheriting is calles subclass
2.) class HandTools: public Tools {
3.) It inherits all the functionality from a superclass and adds ontop of it.

1 Like
  1. It allows to create objects that inherit propertier from other objects. This way we don’t have to redefine proprieties in derived classes.

  2. Roses and tulips inherit from flowers.

  3. Superclass is inherited from a parent class. The subclass inherits the child class.

  4. class tulips : public Flower {…};

  5. The subclass gets all the functionalities of the parent class.

1 Like

1. Why do we need inheritance in C++? - Because it saves double work and it is helpful when it comes ti maintenance.
2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance. An example could be: Feline (supeclass) and lion, lynx, tiger, cat would be subclasses.

1. What is a superclass and what is a subclass? A superclass is the class from which is inherited from and a subclass is a class which inherits.
2. How would you write a public inheritance in C++? class sublass_name : public superclass_name
3. In what ways can a subclass extend the functionality of a superclass? It can extend the functionality by creating chains of reusable classes and thus creating logical chains from general to specific.

1 Like

PART 1:

  1. Because it speeds up general programming by allowing us to define a class in terms of another class, which makes it easier to create and maintain an application. This way we can reuse, extend or modify the attributes and behavior which are defined in other classes.

  2. Living accommodations-------houses-------apartments--------villas---------condos
    In all these we need bathrooms---------kitchens------------roof----------flooring

PART 2:

  1. In an inheritance relationship, the class being inherited is called superclass. It is a class from which many subclasses can be created.

  2. class fruit : public food {
    };

  3. By using the functions of it and the variables. It can add additional members and methods.

1 Like

1. Why do we need inheritance in C++?
There are some small objects that inherit things from bigger ones
2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance.
Car would inherit from vehicle.

1. What is a superclass and what is a subclass?
A Superclass is the bigger main class and a subclass inherits from the superclass

2. How would you write a public inheritance in C++?
class Employee: public Person

3. In what ways can a subclass extend the functionality of a superclass?
It can create new members and methods or override old ones.

1 Like

Why do we need inheritance in C++?**

We would like to have categories in sort of a data identity tree. Different classes get extended by a major class declaration and give specific features or methods for each. Like Apples is a derived class of Fruits.

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

class Citizen
{
public: 
	string name;
	int age;
	double wage; 
	int retiringAt;
	bool conscience;
};

class Labourer : class Citizen;
class Minister : class Citizen
{
	private: bool serviceAimed;
}

What is a superclass and what is a subclass?

Superclass is a term to declare the base class which derived from.
So a subclass is a way to call the derived, child classes in another way of statement.

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

Using public keyword after the decleration of the child class seperated by column sign between.
class ChildClass : public ParentClassToDeriveFrom

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

Aquiring the methods in public(or protected)-declared superclasses.

1 Like
  1. It permits to reuse properties of another objects.
  2. bycicle and cars inherit from vehicle.
  3. The superclass is the origin class (parent class). The subclass is the class inheriting from the superclass (child class)
  4. class Car: public Vehicle {…};
  5. a subclass inherit of all functionalities of the parent class.
1 Like

Part 1

  1. Allows the user to model a relationship between two objects in which the resulting object shares attributes from both of the contributing objects
  2. The on-road rideability and capacity of a station wagon combined with the off-road capability and ruggedness of a truck leads to the modern SUV
    Part 2
  3. A superclass is the source of the inheritance, while the subclass is the result of the inheritance
  4. class name of subclass : public name of superclass
  5. Updates to variables, functions, and methods by the superclass will extend down to the subclass.
1 Like
FIRST ARTICLE:
  1. Why do we need inheritance in C++?

    • inheritance involves creating new objects by directly acquiring the attributes and behaviors of other objects
      and then extending or specializing them.
  2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance.

    • Fruits
      • Apple

    SECOND ARTICLE:

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

    • In an inheritance (is-a) relationship,
      the class being inherited from is called the parent class, base class, or superclass,
      and the class doing the inheriting is called the child class, derived class, or subclass.
  4. How would you write a public inheritance in C++?

    • After the class declaration, we use a colon, the word “public”, and the name of the class we wish to inherit.
      This is called public inheritance.

    class Apple : public Fruit {
    members

};

  1. In what ways can a subclass extend the functionality of a superclass?
    • The subclass can add new methods and new variables or override existing methods.
1 Like
  1. Why do we need inheritance in C++? it allows us to model an ‘is-a’ relationship between two objects.

  2. Give a simple example of objects in the real world that could be modelled in C++ using inheritance. chairs and desks inherit from furniture.

  3. What is a superclass and what is a subclass? the class being inherited from is the superclass and the class doing the inheriting is the subclass.

  4. How would you write a public inheritance in C++? Class Desk : public furniture{}

  5. In what ways can a subclass extend the functionality of a superclass? a subclass can add more detail be more specific than the superclass.

1 Like
  1. to construct complex classes inherited from simpler ones.

  2. Building -> wall -> cavity -> block & brick veneer -> material (mortar, brick, block, etc…)
    Building -> floor -> hard, polished -> concrete -> material (rock, sand, water, etc…)

  3. a superclass is a class that’s inherited from, and a subclass is the recipient of said inheritance.

  4. class (subclass name): public (superclass name) {}

  5. an employee superclass can provide data for many different subclasses with zero relation to each other. Example: construction, clerical work, medical technician, etc…

1 Like

1. Why do we need inheritance in C++?
Inheritance allows us to reuse classes by having other classes inherit their members.
Inheritance helps us to model an “is-a” relationship between different objects.

2. Give a simple example of objects in the real world that could be modeled in C++ using inheritance.
Red and Blue inherit the color class.

3. What is a superclass and what is a subclass?
Superclass: A class that is being inherited.
Subclass: A class that is inheriting.

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

class Derived_class : public Base_class{
//MEMBERS
};

5. In what ways can a subclass extend the functionality of a superclass?
A subclass inherits the attributes and behavior of a superclass and can add its own functionality on top of it.

1 Like
  1. inheritance is necessary in c++, c++ has inherited stuff from the C language. with out inheriting from C, c++ wouldn’t exist.

  2. trees - pine tree

  3. superclass is the class that is being inherited from. the subclass is doing the inheriting.

  4. class pinetree : public tree {};

  5. subclasses can add new methods and override old ones.

1 Like

Article 1:

1.- Because it allows us to create variables that inherit characteristics of a group.

2.- The elements of the periodic table, none of them are the same but can be ordered by their similarities.

Article 2:

1.- The first one inherits characteristics and the second gets the inheritance of the superclass.

2.- class apple : public fruit{
};

3.- The child class has access to all the functions and variables of the superclass, it can override them.

1 Like
  1. heritance allow us to create objects that directly inherits properties of another objects. And so, we don’t have to redefine some properties in our derived class.

  2. bananas and strawberries inherit from fruits.

  3. Subclass is the class that inherits from the superclass.

  4. class Person : public Baseballplayer {

    };

  5. By inheriting the functionality from the superclass and defining their own functions.

1 Like