Sunday, November 10, 2013

Use of "this" keyword with very simple example


class thiss{

int a,b;

thiss(){

a=1;
b=2;}

thiss(int c,int d){
this();
this.a=c;
this.b=d;

}

void displaydata(){

System.out.println("c= "+a);
System.out.println("d= "+b);
}

public static void main(String []arg){

thiss t1= new thiss();
t1.displaydata();

thiss t2= new thiss(3,4);
t2.displaydata();
}}

___________________
Output:

c= 1;
d=2;
c= 3;
d=4;

No comments:

Post a Comment