Difference between Static methods and Instance methods

前端 未结 10 1327
青春惊慌失措
青春惊慌失措 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 06:10

    Difference between Static methods and Instance methods

    1. Instance method are methods which require an object of its class to be created before it can be called. Static methods are the methods in Java that can be called without creating an object of class.

    2. Static method is declared with static keyword. Instance method is not with static keyword.

    3. Static method means which will exist as a single copy for a class. But instance methods exist as multiple copies depending on the number of instances created for that class.

    4. Static methods can be invoked by using class reference. Instance or non static methods are invoked by using object reference.

    5. Static methods can’t access instance methods and instance variables directly. Instance method can access static variables and static methods directly.

    Reference : geeksforgeeks

提交回复
热议问题