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 253 views
1 answer 259 views
1 answer 356 views
2 answers 306 views
306 views asked Jul 5, 2017 by avibootz
1 answer 166 views
166 views asked Feb 4, 2023 by avibootz
1 answer 236 views
...