Professional Documents
Culture Documents
Inheritance Introduction
Inheritance Introduction
What is inheritance.
Acquiring the features of existing class into a new class that is deriving a class from existing class.
If I take an example of automobile engineering then if a car company has designed the car could they
This is a design and based on this design to have manufactured a car just roughly I'm drawing a
picture.
Now the engineers will work on their design and build on that design.
The product is manufactured and many cars sold and manufactured unsold in the market.
No legacy no company is striving to make some new model of the same car.
So a bigger team to have to do the design work right from the beginning again from scratch or they
can
carry on the same features in a new design that is in a new design all the features on board.
Good.
So a new god a new model that does some changes in this form with some changes in this one.
So whatever the new features that they want to add the cat added like samples.
Model A note is a set of Martin but some more extra internal features.
So for making a new model it just matching with the first one they don't have to do the redesigning
work just they can extend the existing design and add a few features and they're designed to come up
So does the example of inheritance acquiring the features of an existing design into a new design.
No.
I can't speak about other examples wholesale like company electronics companies having a television
So they will learn to look out on the new model right from this crash just as they would extend the
existing one and add few features and launch a new Martin.
No.
Like suppose we have a class rectangle although if you do this which is having some land and
cracked
this I'm scribbling here because we all know about this one.
So although maybe you have a class office lot of properties and methods like GetUp members and
functions
everything is ready.
I'll be creating the object of this rectangle already rectangle on one are do agree.
Double Negative we think it looks like this every rectangle has its lint and that these are the objects
of the design.
No.
We want to write a class under the class which is having the features same as rectangles.
So what I can say is I wouldn't see glass cube void that should extend from time to extend from
rectangle
that is including from rectangle.
So on now the objects of keyboard can be created with various dimensions whatever I like
so that's it.
Like an other engineering we have our design and the object of this design and then we have a new
design
that is object of the new design of this new design is bought a lot of the features of the six distinct
design so same maybe they have a rectangular linear design is there and these are the objects these
are objects like the car on the road rectangle in the memory.
So from this.
Now I want under the clause that is cube wide which I feel like I should extend a rectangle.
If I give a hybrid becomes a cowboy so I am saying that keyboard will inherit from a rectangle.
So in this way we can achieve our usability and programming that is that he was able to do for design.
Also if you want to reuse the class which is already this class is perfect it is ever free.
So this is the concept of inheritance so that is the procedure of boarding the features of an existing
Everything from this class will be taken in this form like everything from this it does design up yet
here.
Show visual display of value of x see out X that's what a simple class average done which is having
one day remember that is variable and a functions show which will display the value of that X then I
So does this index know what is the meaning of public why I should write public there.
Does the syntax in C++ for deriving a class so that it says that this class is extending from this class.
So this column is useful for showing extension of a class here in this one.
Everything public that I've been looking at somebody's ability to say by having to have a function void
Now we're going to see that this data clauses having only one variable.
That's right.
I did plus that going to make it a little short like this suppose.
This is a base class and this is derived class and we show an idol upwards to show that the right
classes
inheriting from base class so class will have a out or towards the spirit class.
Now let us grab the objects of these and see what happens.
Okay.
Bees bee.
It will have only variable X this object will have variable X and it is having them matter that is sure.
So as everything is public so I can act so that so I will see beyond X I find twenty five.
So this 35 is a story here and I'm calling show so I will read on the function also here to show that
this object is having two things that is X and show function X. I have set a sturdy frame and be sure
derived d not only create an object of derive class b let us see what other things it will have it is
having its own member why why then it is heading from base class which is having X also.
So yes it is having X also two members front out that it is having a function display at the function
shows available.
So I do have show also on display also do functions of a liberal in this one not get to see that object
of base closings having X and show these two things only but the object of the right class is having
Okay now commit acts of that X Yes I can say deed or X assigned then and deed or y you assign 15
so
this is done and this is 15.
Can I call this function show deed or show what it will display.
Each function will be called C I'm not sure D an object of delay clause but sure is not the issue is
present here.
So this X it will be called upon that B so to list then then if I say d dog displayed then it will display
So that's it.
So here I have objects of base class an object of like class diagram medically that look like this.
This is having X central does having X Y should display only daughter doting father in this class that
these two things are coming from they are coming from base class because it isn't everything.
So that's it.
Does a simple example to show how we can get the features of an existing class including your class
that is inheritance.
So I have taken a very simple example with a variable and a function and particularly how useful we