How to use this to invoke current class method in Java

1 Answer

0 votes
class Test {
    void method1() {
        System.out.println("method1()");
    }
    void method2() {
        this.method1();
    }
}

public class MyClass {
    public static void main(String args[]) {
        Test t = new Test();
        
        t.method2();
    }
}




/*
run:

method1()

*/

 



answered Dec 12, 2020 by avibootz

Related questions

1 answer 160 views
1 answer 174 views
1 answer 273 views
2 answers 196 views
196 views asked Jul 5, 2017 by avibootz
1 answer 84 views
84 views asked Feb 4, 2023 by avibootz
1 answer 154 views
...