#6.1 Java Tutorial | Inheritance

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

For More Queries WhatsApp or Call on : +919008963671

In this lecture we are discussing :
1)What is inheritance?
2)With example and scenario we understand what is inheritance?
3)Multilevel inheritance
4)Type of relationship

#1
In OOPs inheritance is a process of inheriting the properties of one class to another class.
e.g suppose a class has some property and behaviour and want this behaviour and properties to new class with additional property
we are using inheritance to inherit the property of one class to another.

#2
Scenario based example
Suppose we hire a developer and want to made Calculator which can add
two number.
Step 1:
Developer A - created Calc class which has add method and provide .class file to me but not provide source code file.
class Calc {
public void add(int num1,int num2){
}
}

Now i removed that developer from his post and hire new developer but we want to add subtraction functionality to Calculator.
But problem is that if we have Calc class source file then we said to developer B to add subtraction method.
Step 2:
When we have source code file
then,
class CalcAdv{
public void add(int num1,int num2){
}
public void sub(int num1,int num2){
}
}

But developer A does not provide Calc source code we have only Calc .class file.
Now we have one concept of OOPs that can help the developer B.

Step 3:
Now we have concept of inheritance in OOPs
lets us use extending or inheriting method from Calc class.

//inheriting add method from calc
class CalcAdv extends Calc{
public void sub(int num1,int num2){
}
}

class Main{
public static void main(String []args){
CalcAdv obj=new CalcAdv();
}
}

:- This is know as single level inheritance

#3
Multilevel inheritance
class Calc{
public void add(int num1,int num2){
}
}
class CalcAdv extends Calc{
public void sub(int num1,int num2){
}

//Now we can use the property and methods of Calc also
//Single level inheritence
}

class CalcSuperAdv extends CalcAdv{
public void mul(int num1,int num2){

//But here you can use the property and methods of Calc as well as CalcAdv class
//multilevel inheritance we consider Calc, CalcAdv and CalcSuperAdv
}
}

Note:i) Multilevel inheritance allowed in java but Multiple inheritance not allowed in java we shall understand why this not allowed in next lecture
ii)Term- {super, parent, base}-- same meaning and {sub, child, derived}--same meaning

#4
Type of relationship
i)IS-A relationship means one class is a child of another class.
e.g
class Animal{

}
class Lion extends Animal{
//here we found Lion is a animal
}

ii)HAS-A relationship means one class has using property and method of other class but that class is not a parent of current class.
class Bank{
void withdrawMoney(){
}
}

class Hospital{
A obj=new A();
void accessMoney{
}
//here we can see a hospital has a bank access
}

More Learning :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

You explained very clear within 8 minutes! My lecturer took 2 hours to explain this concept and no one understood. Cheers!

nicholastan
Автор

Explained it better in under 10 minutes than the lector in 2 hours, thanks!

lorenzocatalano
Автор

Telusko OP🔥😂

Love this man yr..
I prefer watching his videos instead of my online classes😂❤️

No-tttz
Автор

khub bhalo video baniyechen Navin dada. Besh sohoje bojha jay. Onek Dhonyobad.

tamonashchakrabarti
Автор

Best explanation i've ever seen!! You are amazing tutor

wojtekyt
Автор

thanks for keeping it simple! really helped me understand inheritance. Thanks!

brandonlimpert
Автор

So Fun😂, along with simple explanation of concepts. Appreciate it.

tsp
Автор

It's so fast and understable..I liked it..☺️

shivanijaiswal
Автор

Explained in a very simple way...thank you😀

radhikamogadampally
Автор

Thanks for great explanation! Keep it up :)

hkahlon
Автор

I love this example. This helped me big time!

Jermaine_Jones
Автор

Superb sir good explanation, thanking you sir

venkateshpeddoju
Автор

Wow this was such a nice explanation ! tyvm!

dinguuuus
Автор

Best explanation sir..great job thank you so much

saranyajothi
Автор

Superb, sir. Very good explanation to get the better understanding. Thank you.

mohanrammanikandan
Автор

while(true)
System.out.println("Thank Youuu");

baimuratnusubaliev
Автор

Thank u very much, for this clear explanation

ghaidaaalrawahi
Автор

what's the difference between inheritance and importing then?

masteryoda
Автор

multilevel can enjoy the benefits of the grandparent as well as parent class, then why there was a need of multiple inheritance as it also gets the features of both classes but directly whereas in multilevel it is indirectly.

anushreevirtualgaming
Автор

i know my inheritance is working as netbeans is grabbing the variables in another class but i dont know why there is no output i tried every way i could think of but still it does not show output

GinnaMann