class ThisClass{
void method1(){
System.out.println("it's method1");
}
void method2(){
System.out.println("it's method2");
//method1();//same as this.method1()
this.method1();
}
}
class MainClassofThis{
public static void main(String args[]){
ThisClass obj=new ThisClass();
obj.method2();
}
}
/*
You may invoke the method of the current class by using the this keyword.
If you don't use the this keyword, compiler automatically
adds this keyword while invoking the method.
*/
it's method2
it's method1
Press any key to continue . . .
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.