Class and Object Blog 1

 Create a Square with the method to initialize it's side, Calculate area, perimeter of the square..





package com.ritesh;

class square
{
int side;
public int area()
{
return side*side;
}
public int perimeter()
{
return 4*side;
}

}


public class Main {

public static void main(String[] args) {
square sc=new square();
sc.side=5;
System.out.println("The area of square is "+sc.area());
System.out.println("The perimeter of square is "+sc.perimeter());

}
}




Comments