You are on page 1of 6

Yeah.

Next topic is inheritance.

This is one of the important feature of object oriented programming.

What is inheritance.

Acquiring the features of existing class into a new class that is deriving a class from existing class.

So what does it mean.

Let us understand the tool other engineering examples.

If I take an example of automobile engineering then if a car company has designed the car could they

have designed some God on that same.

This is just a design okay.

This is a design and based on this design to have manufactured a car just roughly I'm drawing a
picture.

They have manufactured a car.

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.

Now this design is successful.

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.

An extra feature of SOC added extra features on our.

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.

This was hatchback notice seated everything the same.

But that was harsh back.

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

with a new design.


They can make manufacture a lot of gods from this design and sell them in the market.

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

model and they are introducing a new model.

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.

Same thing we want in software.

Also in programming also we want to do the same thing.

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.

So we can create various rectangle so these with rectangles.

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.

Well we don't have to rewrite the core.

That was all the data rectangle.

I can simply data on the class symbols.

I want to write a class for Q Boyd.

It is nothing but a rectangular shape only.

But which is also having one extra dimension that is height.

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 I want everything that is there McDonald to be bored here also.

Then when I create an object of to Boyd Boyd C1 C2 C3.

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.

Does the design of the company a class with the programmer.

This is the running program which will create objects.

This is done by a programmer.

So from this.

Objects are created.

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.

You don't have to redesign again from the beginning.

You can reuse the design so same main programming.

Also if you want to reuse the class which is already this class is perfect it is ever free.

We are using it so no we want another class having the same feature.

So just you can inherit a new class from an existing class.

So this is the concept of inheritance so that is the procedure of boarding the features of an existing

class into a new class.

Everything from this class will be taken in this form like everything from this it does design up yet

here.

Plus we can add more features to this fund.

So say maybe we can add more features to this fund.


So like another engineering stream sort of usability of design is there.

So CMB we want to achieve the usability of so scope that is a class.

Now let's see a simple example of inheritance.

Let me like just one example.

Class here see if I have a class card.

Base class base is having everything public.

Let us say it is having variable integer X on having a function that is void.

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

will go to class B arrived and that is inheriting from base class.

So here I will write public base.

So does this index know what is the meaning of public why I should write public there.

I will explain afterwards.

Class derived public base.

So this is inheriting from base class.

So this nematode matter.

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

displaying X with some space y.

This will display two things X and Y.

Now we're going to see that this data clauses having only one variable.

That's right.

That's how it got x.

That X it is bordering are getting it from the base class.

So base class is having X and it just accessing X as well as y.

So that's set as a base class.

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.

See inside meaning matured.

Okay.

Into me mean I mean whatever you want to right.

So no I didn't create the object of bees.

Bees bee.

So what happens when they create an object of bees.

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.

Then I will say bee dog show what will be displayed.

It will be showing displaying x.

So what is the value of X that I have said 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

I am calling so it is displaying the string of five.

Now let us create the object of D-Day plus

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

X show volume and display x.

Sure invite and display all these things on there.

So I'll just very books on this site.

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 will be called on a dispute displaying value of X..

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

these two values x and y so X is standing by is 15.

So the output will be 10 and 15.

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

will learn more on this fun.

Okay let us try this and see how it works.

You might also like