Static Keyword Java Example

Static Keyword Java Example

Previous Home Next

 

Static Keyword Java Example

Static Keyword Java Example
 

 

//program for calculate Area and circumference of a circle usin static keyword..
package
r4r.co.in;

class
Static {

   
static int length = 10
;
   
static int breath = 20
;

   
static void
NewClass() {
       
System.out.println("Length ="
+ length);
       
System.out.println("Breath ="
+ breath);
    }

   
static
{
       
float a = (float
) (length * breath);
        NewClass();
       
System.out.println("Area of rectangle:"
+ a);
       
float b = (float) (2
*( length + breath));
       
System.out.println("Circumference of a rectangle:"
+ b);
    }

   
public static void main(String
[] args) {
    }
}

Length =10
Breath =20
Area of rectangle:200.0
Circumference of a rectangle:60.0

Previous Home Next