int x=22;
long z=24;
//now in this case int is smaller than long so
z=x; // is quite appropriate as it implicitly converts from int to long(widening)
同样,我们有这样的类:
private static class Box {
private int width;
private int height;
private int length;
//...
}
private static class WeightBox extends Box {
private int weight;
//...
}
public class Main {
public static void main(String args[]) {
Box simpleBox = new Box();
WeightBox wt = new WeightBox();
simpleBox = wt; //we can always do this
//wt = simpleBox cannot be done implicitly
//for this to work we have to use type casts
}
}
为什么simpleBox = wt
simpleBox属于基类而wt属于扩展类却能做到?扩展类不应该大于基类吗?