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 166 views
1 answer 185 views
1 answer 283 views
2 answers 203 views
203 views asked Jul 5, 2017 by avibootz
1 answer 92 views
92 views asked Feb 4, 2023 by avibootz
1 answer 159 views
...