chap4-19.txt

来自「清华大学出版社经典教材系列」· 文本 代码 · 共 24 行

TXT
24
字号
// 程序4-19
class point{  
    int x, y;  

    point(int x, int y){    this.x=x;    this.y=y;    }
    int  getX( ){      return  x;    }
}

class circle extends point{         // 从point类派生出子类circle
    int radius;

    circle(int r, int x, int y){    super(x, y);     radius=r;    }
    double area( ){   return Math.PI*radius*radius;   }          // 子类定义的方法
}

public   class  hello {    
    public static void  main(String [ ] args){
        circle  c=new circle(1,1,1);
        point p=c;			// 注意:p的类型和c的类型不同

        System.out.printf("结果是:%d",p.getX( ));  
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?