subclass and extends

    科技2022-07-14  112

    Java looks in the declared (apparent) type of an object to see what methods are available to that object (it doesn’t matter how the object is instantiated).

    Java只会看apparent type, 去寻找里面的有效的methods而不是在actual type里面寻找。

    Example:

    public class Plane() { void takeOff(); void fly(); } // a subclass extends to Plane public class PrivatePlane() extends Plane { void bringWarmTools(); } PrivatePlane pp = new PrivatePlane(); pp.bringWarmTools();// that works Plane plane = new Plane(); plane.bringWarmTools(); //then java will complain
    Processed: 0.013, SQL: 8