Answers for "program to find area of rectangle using constructor in java"

2

Calculate area of rectangle using constructor overloading in java

import java.util.*;
class RectangleShape
{
   int length, breadth;
   // rectangle constructor java
   RectangleShape(int l, int b) 
   { 
      length = l; 
      breadth = b; 
   } 
   RectangleShape(int l) 
   { 
      length = l; 
      breadth = 20; 
   } 
   RectangleShape() 
   { 
      length = 6; 
      breadth = 2; 
   } 
   float getArea() 
   { 
      return(length * breadth); 
   }
}
public class FindArea 
{
   public static void main(String[] args)
   {
      RectangleShape rs1 = new RectangleShape(); 
      RectangleShape rs2 = new RectangleShape(60); 
      RectangleShape rs3 = new RectangleShape(40, 20); 
      System.out.println("First rectangle : " + rs1.getArea()); 
      System.out.println("Second rectangle : " + rs2.getArea()); 
      System.out.println("Third Rectangle : " + rs3.getArea());
   }
}
Posted by: Guest on February-09-2021
1

Calculate area of rectangle using default constructor in java

import java.util.*;
class RectangleShape 
{
   int area, length, breadth; 
   RectangleShape() 
   { 
      length = 50; 
      breadth = 20; 
   } 
   void getArea() 
   { 
      area = length * breadth; 
      System.out.println("Area of Rectangle : " + area); 
   }  
}
public class RectangleAreaConstructor
{
   public static void main(String[] args) 
   {
      RectangleShape rs = new RectangleShape(); 
      rs.getArea();
   }
}
Posted by: Guest on February-09-2021

Code answers related to "program to find area of rectangle using constructor in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language