📄 demo.java~5~
字号:
// 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 ShapeManager{ 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -