📄 shapeinterface.java
字号:
interface Shape
{
void draw();
void erase();
}
//圆
class Circle implements Shape
{
public void draw()
{
System.out.println("circle draw()");
}
public void erase()
{
System.out.println("circle erase()");
}
}
//正方形
class Square implements Shape
{
public void draw()
{
System.out.println("Square square()");
}
public void erase()
{
System.out.println("Square erase()");
}
}
//直线
class Line implements Shape{
public void draw()
{
System.out.println("Line draw()");
}
public void erase()
{
System.out.println("Line erase()");
}
}
public class ShapeInterface
{
static void drawShape(Shape object){
object.draw();
object.erase();
if( object instanceof Circle){
System.out.println("Circle");
}else if( object instanceof Square){
System.out.println("Squalre");
}else if( object instanceof Line){
System.out.println("Line");
}else{
System.out.println("UnKnown...");
}
}
public static void main(String args[])
{
Shape c=new Circle();
Shape s=new Square();
Shape l=new Line();
drawShape(c);
drawShape(s);
drawShape(l);
}
}
/*
if( object instanceof Circle){
System.out.println("Circle");
}else if( object instanceof Square){
System.out.println("Squalre");
}else if( object instanceof Line){
System.out.println("Line");
}else{
System.out.println("UnKnown...");
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -