因为子类继承父类的时候,会继承父类中的数据,所以必须要看父类是如何对自己的数据进行初始化的;- class Fu
- {
- int x;
- int y;
- Fu(){x=1;y=2;}
- Fu(int x,int y){this.x=x;this.y=y;}
- }
- class Zi extends Fu
- {
- int z;
- Zi(){
- //super();
- this.z=3;
- }
- public String toString(){
- return x+","+y+","+z;
- }
- }
- public class Demo2
- {
- public static void main(String[] args){
- Zi zi=new Zi();
- System.out.println(zi);
- }
- }
复制代码
感觉有点勉强:P |