Search This Blog

save java programs with".java" extension

examples :

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

quick links

"this" keyword program2 in java

class square
{
int l;
square()
{

System.out.println("i am in square()");
l=10;
}
square(int x)
{
this();

System.out.println("i am in square(x)");
}
void area()
{
System.out.println("i am in area()");
System.out.println("area of square :"+l*l);
}
public static void main(String args[])
{
square square1=new square();
square1.area();
square square2=new square(20);
square2.area();
}
}
================================================
output :

i am in square()
i am in area()
area of square :100
i am in square()
i am in square(x)
i am in area()
area of square :100