初学 Java 的疑惑
public class fruit{private int fid;
public String color;
public String shape;
public String name;
public float price;
public double sum;
public void buyingfruit(){
System.out.printf("你买的水果是%s,",name);
System.out.printf("%f每斤%n",price);
System.out.printf("你共买了%f斤%n",sum);
System.out.printf("共计%f元%n",price*sum);
}
}
public class Apple extends fruit{
public static void main(String[]args){
Apple apple=new Apple();
apple.color="红色";
apple.name="红富士苹果";
apple.price=2.5f;
apple.shape="圆形";
apple.sum=2.5f;
apple.buyingfruit();
}
}
说是在子类中访问父类的成员变量和方法,可是运行的时候出现这种情况,要在Apple.java文件中声明,该怎么解决?