Search This Blog

save java programs with".java" extension

examples :

helloworld.java
sample.java
match.java
send-mail.java

quick links

parameterized constructor in java

class square
{
int l;
square(int x)
{
System.out.println("inside constructor of square");
l=x;
}
void area()
{
System.out.println("area of square :"+(l*l));
}
}
class demo
{
public static void main(String args[])
{
square s1= new square(10);
s1.area();
square s2= new square(20);
s2.area();
square s3= new square(30);
s3.area();
}
}

==================================================
output :
inside constructor of square
 area of square :100
inside constructor of square
 area of square :400
inside constructor of square

 area of square :900