怎么不能调用brownhorse();
public class horse{
public void darkhorse(String color ,float speed){
System.out.println( "I an " +color );
System.out.println( "My speed is " +speed);
int lon=1000;
float hour;
hour=lon/speed;
System.out.println( "I run 1000 meters "+hour );
System.out.println( "we are sheeping 10 hours. ");
System.out.println();
}
public void brownhorse(String color ,float speed){
System.out.println( "I an " +color);
System.out.println( "My speed is " +speed);
int lon=1000;
float hour;
hour=lon/speed;
System.out.println( "I run 1000 meters "+hour );
System.out.println( "we are sheeping 10 hours. ");
}
class whirehorse extends horse{
}
public static void main(String[] args) {
// TODO Auto-generated method stub
horse p1 = new horse();
p1.darkhorse( "darkhorse ", 30);
horse p2 = new horse();
p2.brownhorse( "brownhorse ", 40);
whirehorse p3= new whirehorse();
p3.brownhorse( "whirehorse ",50);
}
}
怎么不能调用brownhorse();?
帮下忙啊,谢谢。
------解决方案--------------------看的头晕 顶
------解决方案--------------------可以运行,只不过你的whitehorse的定义是放在horse内部的,是inner class(内部类)。如果把它的定义放在horse外面,程序运行正常!