Java10 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Program for Heirarchial Inheritance:-

import java.util.*;

class Shape {
float length, breadth, radius;
}
class rectangle extends Shape {
public rectangle(float l, float b) {
length = 1;
breadth = b;
}
float rectangle_area() {
return length * breadth;
}
}
class circle extends Shape {
public circle(float r) {
radius = r;
}
float circle_area() {
return 3.14f * (radius * radius);
}
}
class square extends Shape {
public square(float l) {
length = l;
}
float square_area() {
return (length * length);
}
}
public class Heirarchial {
public static void main(String args[]) {
rectangle r = new rectangle(2, 5);
System.out.println("Area of rectangle:" + r.rectangle_area());
circle c = new circle(5);
System.out.println("Area of circle:" + c.circle_area());
square s = new square(5);
System.out.println("Area of square" + s.square_area());
}
}

OUTPUT:

You might also like