How to access an object's parent object in Java?

后端 未结 4 1465
既然无缘
既然无缘 2021-01-29 01:36

Have a look at this example:

class Parent{
    Child child = new Child();
    Random r = new Random();
}

class Child{

    public Child(){
        //access a me         


        
4条回答
  •  遇见更好的自我
    2021-01-29 02:00

    • Yes, If it is static method , you can do that (Random.methodName()).

    • If it is an instance method, A big Noooooo. You definitely need Random instance.

提交回复
热议问题