How to pass Object from java class to another java class

前端 未结 6 465
抹茶落季
抹茶落季 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:27

    I know this question is old, but If I'm correct you want to transfer an Object into another class to be used.

    In order to do that you need a few things

    Class XYZ has to have a constructor to take in the parameter "Object" it would something like

    class XYZ{
        private Object ab
        public XYZ(Object ab){
            this.ab = ab;//This is the constructor called when you create an XYZ object, and want to use the Object ab in XYZ
        }
    

提交回复
热议问题