How to pass Object from java class to another java class

前端 未结 6 466
抹茶落季
抹茶落季 2020-12-15 14:34

I created an instance of a class in java as following:

ABC ab = new ABC();

I want to access this instant ab in another class

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 15:06

    You have two ways to pass object parameter to one class to another.

    • Passing parameter to a method

      public void passMethod(ABC ab) {
      }
      
    • Passing parameter to a constructor

      public class XYZ {
      
          public XYZ(ABC ab) {               
          }
      }
      

提交回复
热议问题