this keyword as Method parameter, Using Inheritance

Java Programming Language / Class, Object and Methods in java

1073

Program:

 // this keyword as Method parameter

class ThisAsParameter {

 public static void main(String[] args) {
 Child obj = new Child();
 obj.i = 20;
 obj.method();
 }
}

class Child extends ThisAsParameter {
 int i;

 void method() {
 method1(this);
 }

 void method1(Child t) {
 System.out.println(t.i);
 }
}

Output:

20
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.