Using methods from another class in the main?

后端 未结 3 1178
悲&欢浪女
悲&欢浪女 2021-01-27 03:08

Okay so I did search this question and a decent amount of results showed up. All of them seemed to have pretty different scenarios though and the solutions were different for ea

3条回答
  •  温柔的废话
    2021-01-27 03:51

    You should make displayEditParty function public static and then you can use it in other class by className.displayEditParty(?,?);

    Methods of class can be accessible by that class's object only. Check below code:

    class A{
    
        void methodA(){
            //Some logic
        }
    
        public static void methodB(){
            //Some logic
        }
    }
    
    public static void main(String args[]){
    
        A obj = new A();
        obj.methodA(); // You can use methodA using Object only.
    
        A.methodB();  // Whereas static method can be accessed by object as well as 
        obj.methodB(); // class name.
    }
    

提交回复
热议问题