answersLogoWhite

0


Best Answer

Inheritance allows you to derive new objects from existing objects, thus allowing you to re-use the existing code (known as the generic code), augmenting or overriding that existing code in order to provide more specialised functionality (the specialised code).

For instance, if you have a Rectangle class, you might choose to derive a Square class from the Rectangle class. Thus the Square class inherits all the properties of a Rectangle (such as 4 vertices and 4 edges meeting at 90 degrees), but specialises the class to ensure that all four edges are always equal length. In other words, a Square is a more-specialised form of Rectangle, and therefore need only cater for the properties that are unique to Squares, whilst inheriting all the properties that are common to both Squares and Rectangles.

This is not unlike the real-world where you will often adapt an existing object to suit a new purpose, rather than build a new object completely from scratch, thus saving you a lot of time and money. In other words, we don't spend our time continually re-inventing wheels, we simply use an existing wheel and adapt it to suit our needs. The more closely the existing wheel resembles the wheel we actually want, the less work we have to do to adapt it.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The same way that inheritance helps build families of people. Children inherit genes from their parents and grandparents, just as child classes inherit the public and protected properties of their parent and grandparent classes, the base classes. By inheriting those properties, the most-derive classes are blessed with ready-made functionality. This allows us to create new classes from tried and tested existing classes, creating more specialised classes, without re-writing any of the existing code. We only need to cater for the differences, the specialities.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How inheritance helps in building class hierarchies in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why is the depiction of social hierarchies an important aspect of shakespearean tragedies?

The depiction of social hierarchies in Shakespearean tragedies helps to explore themes of power, authority, and the impact of social class on characters' lives and decisions. It adds layers of complexity to the characters' relationships and motivations, highlighting the consequences of societal expectations and norms on their fates. By examining social hierarchies, Shakespeare delves into the tensions and conflicts that arise within these structures, enriching the narrative and allowing for deeper insights into human behavior.


What do you mean when you say that Java has two concepts?

You are talking about the implementation point view of Abstract class and the interface. Let's go. 1. Interface helps Multiple inheritance:- In java you can't have a class inherited from more than one class, i.e. the multiple inheritance. Interface helps us in implementing the multiple inheritance(virtually), because their is no such restriction in implementing more than one interface. But the Abstract class can't help you doing so. 2. Interface helps global declaration:- In C/C++, a header file holds the declaration of the functions and the symbolic constants. Similarly we can have a interface which is having only the symbolic constants which is same for all classes which implements it. And also the method have only the signature and the class which implements it is free to write the body at his own wish. Abstract class can't help in doing this. 3. Abstract class is more secure:- Because in Interface we have all the things public. But in Abstract class we can have private and also friendly members. 4. Interface is overhead:- Because in Interface we are bound to implement all the methods though some of them we actually need. But in case of the Abstract class we can override the methods which we want.


What vocabulary building strategy makes connections between related words?

Semantic mapping is a vocabulary building strategy that helps make connections between related words by visually organizing them into categories or hierarchies based on their meanings and relationships. This can help learners see patterns and similarities among words, making it easier to remember and use them effectively.


When shall you use Multiple Inheritance?

Multiple inheritance is used when a new class to be formed has to inherit characteristics from two or more classes. eg: class scientist class labourer | | | | V V -------------------------------- | class employee | -------------------------------- Multilevel inheritance is used if a derived class inherits characteristics from a base class which is a derived class (intermmediate base class). If the inheritance level is more than two then it is a multilevel inheritance. eg: class Grandfather | | V class Father | | V class son


What are best paid jobs for people who like drawing and designing?

a arcatechte :P they draw and model building they draw the building first and then they model there drawing so its like art class only to the next level, hope it helps :)


How does inheritance helps prevent errors in programming?

Inheritance is an object oriented feature supported by Java wherein the features of one Java class can be inherited/made available in another class. This creates a parent child relationship between these 2 classes. Class Inheritance in java mechanism is used to build new classes from existing classes. The inheritance relationship is transitive: if class x extends class y, then a class z, which extends class x, will also inherit from class y. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.Example:public class Parent {private String name = "Rocky";public String getName(){return this.name;}}public class Child extends Parent {public static void main(String[] args){System.out.println("Name in Parent is: " + getName());}}Here the getName() method is available only in the parent class but is directly used in the child class because the method is public and is directly accessible to the child class since it has extended the parent class.Benefits of Inheritance:One of the key benefits of inheritance is to minimise the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organisation of code and smaller, simpler compilation units.Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass


Building material that begin with H?

Hammer House-building Hope this helps!


What is the box called that helps show the possible outcome for dominant and recessive gene inheritance?

punnett square


What were the classes on the Titanic?

First-Class, Second-Class, and Third-Class, or Steerage. Hope this helps!


Why you need to use inheritance?

Inheritance is an object oriented programming concept that helps us with the following benefits:You can reuse existing code instead of having to write them againredundancy of code is avoidedrework and maintenance is easy


What helps you to be on time for class?

speed walk or have your stuff with u the class before


What does class president do?

helps with proms and special events. The senior class president is responsible for class reunions and Homecomings .