0% found this document useful (0 votes)
2 views

Java

Inheritance in Java allows one class to acquire properties from another, facilitating a hierarchical organization of information. The class that inherits is called a subclass, while the class being inherited from is the superclass, with the 'extends' keyword used to establish this relationship. An example demonstrates how the 'My_Calculation' class inherits methods from the 'Calculation' class, showcasing the implementation of addition and subtraction methods.

Uploaded by

sakshinaik1803
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java

Inheritance in Java allows one class to acquire properties from another, facilitating a hierarchical organization of information. The class that inherits is called a subclass, while the class being inherited from is the superclass, with the 'extends' keyword used to establish this relationship. An example demonstrates how the 'My_Calculation' class inherits methods from the 'Calculation' class, showcasing the implementation of addition and subtraction methods.

Uploaded by

sakshinaik1803
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

JAVA

INHERITANCE
• Inheritance can be defined as the process where one
class acquires the properties of another. With the use of
inheritance the information is made manageable in a
hierarchical order.
• The class which inherits the properties of other is
known as subclass and the class whose properties are
inherited is known as superclass .
extends Keyword
• extends is the keyword used class Super{
to inherit the properties of a .....
class. Below given is the .....
syntax ofextends keyword. }
class Sub extends
• Syntax:- Super{
.....
.....
}
Sample Code
• Below given is an example demonstrating Java inheritance. In this example you can observe twoclasses
namely Calculation and My_Calculation.
• Using extends keyword the My_Calculation inherits the methods addition and Subtraction of
Calculation class.
• Copy and paste the program given below in a file with name My_Calculation.java

class Calculation{
int z; public class My_Calculation extends
public void addition(int x, int y){ Calculation{
z=x+y; public void m ultiplication(int x,
System .out.println("The sum of the int y){
given num bers:"+z); z=x* y;
} System .out.println("The product of
public void Substraction(int x,int the given num bers:"+z);
y){ }
z=x-y; public static void m ain(String
System .out.println("The difference args[]){
between the given num bers:"+z); Int a=20, b=10;
} My_Calculation obj= new
} My_Calculation();
obj.addition(a, b);
obj.Substraction(a, b);
TYPES OF INHERITANCE

You might also like