The difference between class methods and instance methods in Java

Source: Internet
Author: User
Tags instance method

Instance methods can manipulate instance variables of the current object, or they can manipulate class variables, but class methods cannot access instance variables. The instance method must be called by the instance object, and the class method can be called directly by the class name, in addition to being called by the instance object.

In addition, you cannot use this or super in a class method. There are some restrictions on the use of class methods:

1 object variables cannot be referenced in a class method.

2 The super, this keyword cannot be used in a class method.

The 3 class method cannot invoke an object method in a class.

There are few limitations to instance methods compared to class methods:

1 instance methods can reference object variables (which is obvious), or they can reference class variables.

The super, the This keyword can be used in 2 instance methods.

A class method can be called in a 3 instance method.

The difference between class methods and instance methods in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.