This document demonstrates single-level inheritance in Java by defining a Parentclass with methods for addition, subtraction, and division. A Subclass extends the Parentclass and adds an area() method. A main method in another class creates an instance of the Subclass and calls all methods, including those inherited from the Parentclass.
This document demonstrates single-level inheritance in Java by defining a Parentclass with methods for addition, subtraction, and division. A Subclass extends the Parentclass and adds an area() method. A main method in another class creates an instance of the Subclass and calls all methods, including those inherited from the Parentclass.
This document demonstrates single-level inheritance in Java by defining a Parentclass with methods for addition, subtraction, and division. A Subclass extends the Parentclass and adds an area() method. A main method in another class creates an instance of the Subclass and calls all methods, including those inherited from the Parentclass.
This document demonstrates single-level inheritance in Java by defining a Parentclass with methods for addition, subtraction, and division. A Subclass extends the Parentclass and adds an area() method. A main method in another class creates an instance of the Subclass and calls all methods, including those inherited from the Parentclass.
{ public void add() { int a=10,b=20; System.out.println("Addition of two nos:"+(a+b)); }
public void sub()
{ int a=20,b=10; System.out.println("Subtraction of two nos:"+(a-b)); }
public void div()
{ int a=10,b=5; System.out.println("DIvision of two nos:"+(a/b)); }
} //sub class
package Inheritance;
public class subclass extends Parentclass
{ //This is class for area calculation
public void area()
{ int side=5; System.out.println("Area of square:"+(side*side)); }
//call from main class from other class
package Inheritance; public class singlelevel_inheritance { public static void main(String [] args) { subclass s1=new subclass(); System.out.println("***Method of subclass***");
s1.area(); //method of subclass
System.out.println(""); //method call of parent class through subclass System.out.println("***Methods of super-class***"); s1.add(); s1.sub(); s1.div(); } }