dalang1234 发表于 2008-6-6 13:45

请教:希望高手帮帮忙

要求:设计一个接口名为Shape, 该接口有一个方法名为drow(), 另分别设计一个类名为Rect和Circle类, 这这两个类都继承Shape接

口, 其中Rect类的drow()方法显示”我是矩形”, Circle类的drow()方法显示”我是园形”, 另再设计一个类运行显示这两个类的

draw()的调用.
希望高手帮一下!~

meteor57 发表于 2008-6-6 13:56

找一下书上关于接口的实现的例子,对照一下,其实,不是那么难的.

meteor57 发表于 2008-6-7 21:18

interface Shape
{
        void drow();
}
class Rect implements Shape
{
        public void drow()
        {
                System.out.println("我是矩形");
        }
}
class Circle implements Shape
{
        public void drow()
        {
                System.out.println("我是圆形");
        }
}

public class Interfaceexample {
        public static void main(String[] args) {
                Rect re = new Rect();
                Circle ci = new Circle();
                re.drow();
                ci.drow();
        }
}

页: [1]

编程论坛