static int score1 = 86;
static int score2 = 92;
HelloWorld hello = new HelloWorld();
int allScore = hello.sum();
public int sum() {
return allScore;
}
public static void main(String[] args) {
int allScore = score1+score2;
System.out.println("总分:" + allScore);
}
static int score2 = 92;
HelloWorld hello = new HelloWorld();
int allScore = hello.sum();
public int sum() {
return allScore;
}
public static void main(String[] args) {
int allScore = score1+score2;
System.out.println("总分:" + allScore);
}
2016-05-07
在该节代码中,在main()函数中,要使用内部类的方法时,首先创建了一个外部类对象,在创建内部类对象时,通过外部类对象.new 内部类()的形式。可以理解为:要使用内部类的方法,首先需要将外部类实例化为一个对象,然后通过外部类的对象对内部类进行实例化,最后再调用内部类的方法。就好比文件系统,你要找一个文件,首先需要知道它在哪个盘,然后再找对应的文件夹。
2016-05-06
定义跳刀
public class tiaodao{
// 定义跳刀的属性
int price;//跳刀的价格
int distance;//跳刀跳的距离
// 定义跳刀的方法
void use(){
System.out.println("我能闪现1200码的距离");
}
}
public class tiaodao{
// 定义跳刀的属性
int price;//跳刀的价格
int distance;//跳刀跳的距离
// 定义跳刀的方法
void use(){
System.out.println("我能闪现1200码的距离");
}
}
2016-05-06
public class HelloWorld {
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println(HelloWorld.className);
}
}
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println(HelloWorld.className);
}
}
2016-05-06
public class HelloWorld {
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println(className);
}
}
// 定义静态变量,保存班级名称
static String className = "JAVA开发一班";
public static void main(String[] args) {
// 访问静态变量,输出班级名称
System.out.println(className);
}
}
2016-05-06