public class MonstorText {
public static void main (String[] args){
Monstor[] ma = new Monstor[2];
ma[0] = new Monstor();
ma[1] = new Vampore();
for(int i=0; i<2; i++){
ma[i].frighten(i);
}
}
}
public class Monstor {
boolean frighten(int x){
System.out.print("fire");
return true;//调用此方法的对象不要求返回值,返回true或false均可
}
}
public class Vampore extends Monstor {
int frighten(int x){//报错,子类继承自父类的方法必须相同(包括返回类型,名称,参数列表)
System.out.print("arrrgh");
return 1;
}
}
public static void main (String[] args){
Monstor[] ma = new Monstor[2];
ma[0] = new Monstor();
ma[1] = new Vampore();
for(int i=0; i<2; i++){
ma[i].frighten(i);
}
}
}
public class Monstor {
boolean frighten(int x){
System.out.print("fire");
return true;//调用此方法的对象不要求返回值,返回true或false均可
}
}
public class Vampore extends Monstor {
int frighten(int x){//报错,子类继承自父类的方法必须相同(包括返回类型,名称,参数列表)
System.out.print("arrrgh");
return 1;
}
}