⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapeinterface.java

📁 java基础编程的教程! 是内部培训的资料! 对java基础教学很好哦!
💻 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 + -