JAVA based learning - a class method

Class method: also known as static methods

object method: also known as instance methods, non-static method

to access an object method, must be based on the premise that there is a target on
access class methods, there is not need to object directly access

And access class attributes , like calling a class method, there are two ways
1. Object Class Methods

garen.battleWin ();

2. Class Class Method

Hero.battleWin();

Both approaches can call the class method, but it is recommended to use the second kind. Class methods are the way, which is more in line with the understanding of semantics.
And in many cases, and no examples, such as when used in the previous practice of obtaining random numbers approach

Math.random()

random () is a class method, the class to be called directly by Math, Math exists and no instance.

 

If one method, the calling object properties, such as

public String getName(){
return name;
}

The name attribute is the object attributes, only a specific object exists when, name makes sense. If the method in accessing the object properties, then this method, it must be designed as an object method

Guess you like

Origin www.cnblogs.com/leemlzm/p/12077813.html