Sunday, January 31, 2016

TestThisKeyword

package Constructor;

public class TestThisKeyword {

int a;
int b;
int c;
static int d;

TestThisKeyword() {
System.out.println("I am default constructor");
}
TestThisKeyword(int a, int b) {
this();
System.out.println("I am from parameterised constructor with 2 argument");
this.a = a;
this.b = b;

}

TestThisKeyword(int a, int b, int c){
 this(a,b);
 System.out.println("I am from parameterised constructor with 3 argument");
 this.c = c;
}

void display(){
System.out.println("value of a, b, c is:-"+a+","+b+","+c);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestThisKeyword obj = new TestThisKeyword(2,3,4);
obj.display();
}

}

No comments:

Post a Comment