package Test;
/*
* Note: subclasses cannot inherit the private members of the parent class (private), and cannot inherit the constructors of the parent class
* The child class has all the members of the parent class, except for private and constructors
* If the method of the parent class is subclassed If the class is overridden, the subclass method is called
*
*/
public class ExtendsOne {
public static void main(String[] args) {
Apple a=new Apple();
a.weight=10.21;
a.info();//10.21
a.fun();//The subclass method overrides fun( )
}
}
class Fruit{
public double weight;
public void info() {
System.out.println(weight);
}
public void fun()
{
System.out.println("父类方法fun()");
}
}
class Apple extends Fruit{
public void fun()
{
System.out.println("子类方法重写了fun()");
}
}