开发者社区 问答 正文

接口的定义与使用中关于主方法是一个客户端的代码是什么?

已解决

接口的定义与使用中关于主方法是一个客户端的代码是什么?

展开
收起
JWRRR 2022-04-03 13:59:52 1395 分享 版权
1 条回答
写回答
取消 提交回答
  • 推荐回答

    interface IFruit { // 定叉一个描述水果的操作

    public void eat() ; // 吃水果

    }

    class Apple implements IFruit {

    public void eat() {

       System.out.println("削皮吃苹果! ") ;
    

    }

    }

    public class TestDemo {

    public static void main (String args[]) {
    

    // 子类为接口进行对象的实例化处理

        IFruit fruit = new Apple() ;
    
        fruit.eat();
    

    }

    2022-04-03 14:29:59
    赞同 展开评论
问答地址: