Home > Java > JavaBase > The difference between class methods and instance methods in java

The difference between class methods and instance methods in java

王林
Release: 2019-11-16 15:12:09
Original
4758 people have browsed it

The difference between class methods and instance methods in java

1. Class method

Class method is a static method and needs to be modified by the static modifier in front. Variables cannot be included in class methods.

1. The object method of the class cannot be called

2. The object variable cannot be referenced

3. The class method cannot be overridden (overwritten)

4 , Class methods cannot use super, this keyword

2. Instance methods

1. You can call the object method of the class

2. You can quote Object variables

3. Instance methods can be overridden (overwritten)

4. Instance methods can use super, this keyword

Difference:

The class method is assigned a memory address when the class is loaded, so it can be called by any object after loading, and can be called directly through the class name (class name. method name), while the instance method needs to be created after The memory address will be allocated after the object.

Recommended tutorial: Java tutorial

The above is the detailed content of The difference between class methods and instance methods in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template