shapeinterface.java
来自「java基础编程的教程! 是内部培训的资料! 对java基础教学很好哦!」· Java 代码 · 共 78 行
JAVA
78 行
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 + =
减小字号Ctrl + -
显示快捷键?