demo.java~2~

来自「提供了常用的JAVA技术的示例」· JAVA~2~ 代码 · 共 57 行

JAVA~2~
57
字号
// 5-22 如何运用抽象类。package Demo;abstract class Shape{    int position_x,position_y; // 坐标 变量    void MoveTo(int new_pos_x,int new_pos_y){        position_x=new_pos_x;        position_y=new_pos_y;    }    abstract void draw(); // 抽象方法}class Square extends Shape{    int length;    void draw(){        System.out.println("this is a square.");    }}class  Circle extends Shape{    int radius;    void draw(){        System.out.println("this is a circle.");    }}class Trigon extends Shape{    int bottom;    int highness;    void show(){        System.out.println("this is a trigon.");    }}class ShapManager{    void manager(Shape obj){        obj.draw();    }}public class Demo {    public static void main(String args[]){        ShapeManager shape_man=new ShapeManager();        Square sq=new Square();        Circle ci=new Circle();        Trigon tr=new Trigon();        shape_man.manager(sq);        shape_man.manager(ci);        shape_man.manager(tr);    }}

⌨️ 快捷键说明

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