Categories
Uncategorized

Single Inheritance

Simple example of single inheritance

import java.util.Scanner;

class rectangle

{

double length, breadth;

void get()

{

Scanner a= new Scanner(System.in);

System.out.println(“enter lenght and breadth:”);

length=a.nextDouble();

breadth=a.nextDouble();

}

void display()

{

double ar;

ar=length*breadth;

System.out.println(“Area of Rectangle:”+ar);
}

}

class square extends rectangle

{

void display()

{

super.display();

double ar;

ar=length*length;

System.out.println(“Area of Square:”+ar);
}

}

class area

{

public static void main(String args[])

   {

    square s=new square();

    s.get();

    s.display();
}

}