Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
2980いいね 229,969 views回再生

#6.1 Java Tutorial | Inheritance

Check out our courses:

AI Powered DevOps with AWS - Live Course :- https://go.telusko.com/AIDevOps-AWS
Coupon: TELUSKO10 (10% Discount)

Complete Java Developer Course Batch-4: https://go.telusko.com/Complete4
Coupon: TELUSKO10 (10% Discount)

Master Java Spring Development : https://go.telusko.com/masterjava
Coupon: TELUSKO20 (20% Discount)

Udemy Courses:

Spring: https://go.telusko.com/udemyteluskosp...
Java:- https://go.telusko.com/udemyteluskojava
Java Spring:- https://go.telusko.com/Udemyjavaspring
Java For Programmers:- https://go.telusko.com/javaProgrammers
Python : https://go.telusko.com/udemyteluskopy...
Git : https://go.telusko.com/udemyteluskogit
Docker : https://go.telusko.com/udemyteluskodo...

For More Queries WhatsApp or Call on : +919008963671

website : https://courses.telusko.com/

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){
System.out.println(num1+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){
System.out.println(num1+num2);
}
public void sub(int num1,int num2){
System.out.println(num1-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){
System.out.println(num1-num2);
}
}


class Main{
public static void main(String []args){
CalcAdv obj=new CalcAdv();
obj.add(5,4);
obj.sub(5,4); //now we can use addition and subtraction functionality
}
}

:- This is know as single level inheritance

#3
Multilevel inheritance
class Calc{
public void add(int num1,int num2){
System.out.println(num1+num2);
}
}
class CalcAdv extends Calc{
public void sub(int num1,int num2){
System.out.println(num1-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){
System.out.println(num1*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(){
System.out.println("withdrawl);
}
}

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


Instagram :   / navinreddyofficial  
Linkedin :   / navinreddy20  
Discord :   / discord  

More Learning :

Java - https://bit.ly/3xleOA2
Python :- https://bit.ly/3H0DYHx
Django :- https://bit.ly/3awMaD8
Spring Boot :- https://bit.ly/3aucCgB
Spring Framework :- https://bit.ly/3GRfxwe

Servlet & JSP :- https://bit.ly/3mh5CGz
Hibernate Tutorial :- https://bit.ly/3NWAKah
Rest API | Web Service Tutorial :- https://bit.ly/38RJCiy

Git :- https://bit.ly/3NUHB3V
JavaScript :- https://bit.ly/3mkcFys
Kotlin :- https://bit.ly/3GR2DOG


Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
http://www.telusko.com/contactus

コメント