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 163 views
1 answer 176 views
1 answer 280 views
2 answers 198 views
198 views asked Jul 5, 2017 by avibootz
1 answer 87 views
87 views asked Feb 4, 2023 by avibootz
1 answer 157 views
...