父类:
public class Traffic {
int people;
String place;
public void run()
{
System.out.println(people+"个人"+"在"+place);
}
}
子类:
public class Car extends Traffic {
}
public class ferry extends Traffic {
}
public class Aircraft extends Traffic {
}
测试类:创建对象 指定子类
对属性复制 调用父类的方法
public class Traffic {
int people;
String place;
public void run()
{
System.out.println(people+"个人"+"在"+place);
}
}
子类:
public class Car extends Traffic {
}
public class ferry extends Traffic {
}
public class Aircraft extends Traffic {
}
测试类:创建对象 指定子类
对属性复制 调用父类的方法
2015-07-05
static int score1 = 86;
static int score2 = 92;
static int sum = 0;
public static int sum() {
sum = score1 + score2;
return sum;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
static int score2 = 92;
static int sum = 0;
public static int sum() {
sum = score1 + score2;
return sum;
}
public static void main(String[] args) {
int allScore = sum();
System.out.println("总分:" + allScore);
}
}
2015-07-04
System.out.println("访问外部类中的score:" + HelloWorld.this.score );//加上this就出错了
2015-07-03