Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Inheritance in Java

Uploaded by

Rudresha CE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Inheritance in Java

Uploaded by

Rudresha CE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

INHERITANCE IN JAVA

WHY DO WE NEED JAVA INHERITANCE ?

• Code Reusability
• Method Overriding
• Abstraction
IMPORTANT TECHNOLOGIES USED IN JAVA
INHERITANCE

• Class
• Super Class
• Sub Class
• Reusability
HOW TO USE INHERITANCE IN JAVA?

Using Extend Keyword


Syntax:
class DerivedClass extends BaseClass
{
//methods and fields
}
Inheritance in java Example:
import java.io.*;
//base or super class
class Employee
{
int salary = 6000;
}
// inherited or sub class
class Engineer extends Employee
{
int benefit = 10000;
}
// driver class
class Gfg
{
public static void main(String args[])
{
Engineer E1 = new Engineer();
system.out.Println(“Salary :” + E1.salary + “\nBenefits :” +E1.benefits);
}
}
JAVA INHERITANCE TYPES

• Single Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance
ADVANTAGES OF INHERITANCE IN JAVA

• Code Reusability
• Abstraction
• Class Hierarchy
• Polymorphism
DISADVANTAGES OF INHERITANCE IN JAVA

• Complexity
• Tight coupling
THANK YOU

You might also like