import java.io.*;
public class Test {
public static void main(String[] args) {
Circle circle=new Circle();
Trangle trangle= new Trangle();
Square square=new Square();
Shape shape1=new Shape();
Shape[]myshape={circle,trangle,square};
shape1.draw();
shape1.erase();
myshape[0].draw();
myshape[0].erase();
myshape[1].draw();
myshape[1].erase();
myshape[2].draw();
myshape[2].erase();
}
}
class Shape {
/**
* The constructor for class Shape
*/
public Shape() {
System.out.println("Inside constructor of Shape");
}
/**
* The draw method can not draw anything because it has nothing to draw.
*/
public void draw() {
System.out.println("The draw method in Shape");
}
/**
* The erase method can not erase anything because it has nothing to
* erase.
*/
public void erase() {
System.out.println("The erase method in Shape");
}
}
class Circle extends Shape {
public Circle() {
System.out.println("Inside constructor of Circle");
}
public void draw() {
System.out.println("The draw method in Circle");
}
/**
* The erase method can not erase anything because it has nothing to
* erase.
*/
public void erase() {
System.out.println("The erase method in Shape");
}
}
class Square extends Shape {
public Square() {
System.out.println("Inside constructor of Square");
}
public void draw() {
System.out.println("The draw method in Square");
}
/**
* The erase method can not erase anything because it has nothing to
* erase.
*/
public void erase() {
System.out.println("The erase method in Shape");
}
}
class Trangle extends Shape {
public Trangle() {
System.out.println("Inside constructor of Trangle");
}
public void draw() {
System.out.println("The draw method in Trangle");
}
/**
* The erase method can not erase anything because it has nothing to
* erase.
*/
public void erase() {
System.out.println("The erase method in Shape");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
编写一个接口Shape类,Rectangle、Triangle、Square等三个类实现(implements)接口Shape,并通过实现Shape中的接口来实现具体功能。 编写两个接口Phone、GameMachine,MobilePhone类实现接口Phone和GameMachine中接口。
资源推荐
资源详情
资源评论
收起资源包目录
接口的应用Shape类,Rectangle、Triangle、Square.zip (2个子文件)
20101610303冯才效多态
AbtractTest.java 2KB
Test.java 2KB
共 2 条
- 1
资源评论
- nowOrNever_2014-06-29一些面试题里会有这道题,大概是子类和基类的一些实际例子,需要准备笔试又对继承不太懂的可以下载看看,意义不是很大
MicheliaC
- 粉丝: 0
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功