Hello Everyone,
In this video we will learn about
1. What is inheritance with real life examples
2. Syntax of inheritance
3. Types of inheritance
Syntax:
Inheritance Example:
class Employee
{
float salary=34534*12;
}
public class Executive extends Employee
{
float bonus=3000*6;
public static void main(String args[])
{
Executive obj=new Executive();
//Accessing salary variable of parent class
System.out.println("Total salary credited: "+obj.salary);
System.out.println("Bonus of six months: "+obj.bonus);
}
}
Types of Inheritance:
Single Inheritance:
class Father
{
//functionality
}
class Child extends Father
{
//functionality
}
MultiLevel Inheritance:
class Father
{
//functionality
}
class Child extends Father
{
//functionality
}
class GrandChild extends Child
{
//functionality
}
Hierarchical Inheritance:
class Father
{
//functionality
}
class Child1 extends Father
{
//functionality
}
class Child2 extends Father
{
//functionality
}
Hybrid Inheritance:
class Father
{
//functionality
}
class Child1 extends Father
{
//functionality
}
class Child2 extends Father
{
//functionality
}
class GrandChild extends Child1
{
//functionality
}
Multiple Inheritance:
we will learn it in coming videos
#java
#Inheritance