Java接口练习中问题 下载本文

内容发布更新时间 : 2025/2/13 20:25:27星期一 下面是文章的全部内容请认真阅读。

1、

public interface Utility { private int Max_SIZE = 20; int MIN_SIZE=10; void use(){ System.out.println(\); } private int getSize(); }

1、

Illegal modifier for the interface field Utility.Max_SIZE; only public, static & final are permitted

Illegal modifier for the interface method getSize; only public & abstract are permitted Abstract methods do not specify a body

2、 3、

三个错误的简记

2、

package cn.bdqn.execise; public interface Utility { }

package cn.bdqn.execise;

class FourWheeler implements Utility{} class Car extends FourWheeler{} class Bus extends FourWheeler{}

public class Test { public static void main(String[] args) { Utility car=new Car(); FourWheeler bus=new Bus(); Utility ut =new Utility(); Bus bus=new FourWheeler(); } }

黄色部分是显然错误的。 绿色部分是正确的。 但绿色的第一句很独特。