A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© bayshier 中级黑马   /  2014-9-18 09:08  /  982 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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()中,创建这个类的对象,然后将它作为参数传递给那四个方法。

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马