Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- * Write a program to calculate square area. Program should have class called
- * square with length as member variable and getArea member method.
- * getArea method should print area of the square object.
- */
- class Square{
- int l;
- void setData(int x){
- l = x;
- }
- void getArea(){
- System.out.println("Area of Square: " + (l*l));
- }
- }
- public class SquareArea
- {
- public static void main(String args[]){
- Square s1 = new Square();
- s1.setData(10);
- s1.getArea();
- Square s2 = new Square();
- s2.setData(4);
- s2.getArea();
- }
- }

Post new comment