|
The use of static methods:
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m02/4b/cd/wkiol1qz4yjwzfanaamrlkzhlii465.jpg "title=" 5.png "width=" height= "296" border = "0" hspace= "0" vspace= "0" style= "width:450px;height:296px;" alt= "wkiol1qz4yjwzfanaamrlkzhlii465.jpg"/>
Example: In the editor, two static variables score1 and score2 are defined respectively to save the score information. Defines a static method sum, which calculates the score score, and outputs the score score in the main method by calling the static method
public class HelloWorld {
Defining Static Variables Score1
static int score1 = 86;
Defining Static Variables Score2
static int score2 = 92;
Defines the static method sum, calculates the score score, and returns the total score
public static int sum () {
return score1+score2;
}
public static void Main (string[] args) {
Call the static method sum and receive the return value
int allscore = Helloworld.sum ();
SYSTEM.OUT.PRINTLN ("Total score:" + Allscore);
}
}
|