Tuesday, February 24, 2009

example code this keyword in constuctor



class Sample4
{
Sample4()
{
this(10); // using this keyword to call overloaded constructors
System.out.println(“hai”);
}
Sample4(
int i)
{
System.out.println(i);
}
public static void main(String ar[])
{
Sample4 s1=
new Sample4();
Sample4 s2=
new Sample4(10);
}
}

output:
10
hai
10

0 comments:

Post a Comment