Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Write a program to calculate square area

  1. /*
  2.  * Write a program to calculate square area. Program should have class called
  3.  * square with length as member variable and getArea member method.
  4.  * getArea method should print area of the square object.
  5.  */
  6.  
  7. class Square{
  8.  
  9.  int l;
  10.  
  11.  void setData(int x){
  12.   l = x;
  13.  }
  14.  
  15.  void getArea(){
  16.  
  17.   System.out.println("Area of Square: " + (l*l));
  18.  }
  19. }
  20.  
  21. public class SquareArea
  22. {
  23.  public static void main(String args[]){
  24.  
  25.   Square s1 = new Square();
  26.   s1.setData(10);
  27.   s1.getArea();
  28.  
  29.   Square s2 = new Square();
  30.   s2.setData(4);
  31.   s2.getArea();
  32.  }
  33. }
Your rating: None Average: 4.3 (4 votes)
Share this

Post new comment