program to find area of rectangle using inheritance in java

Solutions on MaxInterview for program to find area of rectangle using inheritance in java by the best coders in the world

showing results for - "program to find area of rectangle using inheritance in java"
Myles
26 May 2018
1// Program to find area of rectangle using inheritance in java
2class RectangleDimension
3{
4   int length;
5   int breadth;
6}
7class Rectangle extends RectangleDimension
8{
9   int area;
10   void findArea()
11   {
12      area = length * breadth;
13   }
14}
15public class AreaOfRectangleUsingInheritance 
16{
17   public static void main(String[] args) 
18   {
19      Rectangle obj = new Rectangle();
20      obj.length = 50;
21      obj.breadth = 20;
22      obj.findArea();
23      int area = obj.length * obj.breadth;
24      System.out.println("Area of rectangle is: " + area);
25   }
26}