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 151 views
1 answer 166 views
1 answer 263 views
2 answers 190 views
190 views asked Jul 5, 2017 by avibootz
1 answer 77 views
77 views asked Feb 4, 2023 by avibootz
1 answer 148 views
...