Difference between Static methods and Instance methods

前端 未结 10 1312
青春惊慌失措
青春惊慌失措 2020-11-22 05:30

I was just reading over the text given to me in my textbook and I\'m not really sure I understand what it is saying. It\'s basically telling me that static methods or class

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 05:51

    The behavior of an object depends on the variables and the methods of that class. When we create a class we create an object for it. For static methods, we don't require them as static methods means all the objects will have the same copy so there is no need of an object. e.g:

    Myclass.get();
    

    In instance method each object will have different behaviour so they have to call the method using the object instance. e.g:

    Myclass x = new Myclass();
    x.get();
    

提交回复
热议问题