How to use this as argument in a method in Java

1 Answer

0 votes
class Test {
    String s = "java";
    
    void method1(Test m1) {
        System.out.println("method1(Method m1)");
        System.out.println(m1.s);
    }
    void method2() {
        method1(this);
    }
}

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




/*
run:

method1(Method m1)
java

*/

 



answered Dec 12, 2020 by avibootz

Related questions

1 answer 179 views
1 answer 159 views
1 answer 176 views
1 answer 174 views
1 answer 272 views
...