黑马程序员技术交流社区
标题: java 习题分享 第六弹! [打印本页]
作者: bayshier 时间: 2014-9-18 09:08
标题: java 习题分享 第六弹!
1. 证明接口内所有的方法都自动是public的。
2. 在Sandwich.java中,创建接口FastFood并添加合适的方法,然后修改Sandwich以实现FastFood接口。
class Meal {
Meal() { System.out.println("Meal()"); }
}
class Bread {
Bread() { System.out.println("Bread()"); }
}
class Cheese {
Cheese() { System.out.println("Cheese()"); }
}
class Lettuce {
Lettuce() { System.out.println("Lettuce()"); }
}
class Lunch extends Meal {
Lunch() { System.out.println("Lunch()"); }
}
class PortableLunch extends Lunch {
PortableLunch() { System.out.println("PortableLunch()");}
}
public class Sandwich extends PortableLunch {
private static Test monitor = new Test();
private Bread b = new Bread();
private Cheese c = new Cheese();
private Lettuce l = new Lettuce();
public Sandwich() {
System.out.println("Sandwich()");
}
public static void main(String[] args) {
new Sandwich();
}
}
3. 创建三个接口,使之各有两个方法。再创建一个新的接口,继承三者,并添加一个新方法。然后创建一个类,在实现此新接口的同时,继承一个实际的类。并为这个类写四个方法,每个方法分别以四个接口中的一个作为参数。在main()中,创建这个类的对象,然后将它作为参数传递给那四个方法。
| 欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) |
黑马程序员IT技术论坛 X3.2 |