问题又来了
class Cleanser {
private String s = new String("Cleanser");
public void append(String a) { s += a; }
public void dilute() { append(" dilute()"); }
public void apply() { append(" apply()"); }
public void scrub() { append(" scrub()"); }
public void print() { System.out.println(s); }
public static void main(String[] args) {
Cleanser x = new Cleanser();
x.dilute(); x.apply(); x.scrub();
x.print();
}
}class Detergent extends Cleanser {
// Change a method:
public void scrub() {
super.append(" Detergent.scrub()");
super.scrub(); // Call base-class version
}
// Add methods to the interface:
public void foam() { append(" foam()"); }
// Test the new class:
public static void main(String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub(); //??这个怎么能知道调用的是Cleanser.scrub()还是Detergent.scrub()
x.foam();
x.print();
System.out.println("Testing base class:");
Cleanser.main(args); //??这里为什么不能用super.main(args),还有参数args是什么意思
}
}
class Cleanser {
private String s = new String("Cleanser");
public void append(String a) { s += a; }
public void dilute() { append(" dilute()"); }
public void apply() { append(" apply()"); }
public void scrub() { append(" scrub()"); }
public void print() { System.out.println(s); }
public static void main(String[] args) {
Cleanser x = new Cleanser();
x.dilute(); x.apply(); x.scrub();
x.print();
}
}class Detergent extends Cleanser {
// Change a method:
public void scrub() {
super.append(" Detergent.scrub()");
super.scrub(); // Call base-class version
}
// Add methods to the interface:
public void foam() { append(" foam()"); }
// Test the new class:
public static void main(String[] args) {
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub(); //??这个怎么能知道调用的是Cleanser.scrub()还是Detergent.scrub()
x.foam();
x.print();
System.out.println("Testing base class:");
Cleanser.main(args); //??这里为什么不能用super.main(args),还有参数args是什么意思
}
}
解决方案 »
- java与数据库的简单实例
- Spring 的 jdbcTemplate 对于那些只返回简单类型的查询如何处理?
- 我用socket模拟了一个聊天系统,怎样在同一台机子上跑起来呢???
- 如何能吧中间绿字的那部分用进去
- 根据日期(20050907)获得这是星期几?
- 大家好,我有一个问题想请教一下
- 如何在Windows平台上获得WinXP效果的界面?
- 要研究Java的API,有什么好书吗?
- JAVA中数组排列和筛选的问题,请高手提供最有效的方法和代码,高分赠送!!!
- 多线程计时器
- 急急急,壓縮 有中文名的文件 後 在壓縮文件中無法正常顯示中文 文件名 幫忙看一下
- 今天冬至,散分.还有希望考试不要挂科!!!在问一个<接口>问题~~~~
多态,调用的是运行时的类型的方法,子类覆盖了父类的,当然调用子类的。 Cleanser.main(args); //??这里为什么不能用super.main(args),还有参数args是什么意
静态方法怎么用super?
args是命令行参数
多态,调用的是运行时的类型的方法,子类覆盖了父类的,当然调用子类的。
------------------------------------------------------------------
如果我想调用Cleanser.scrub()改怎么做?
谢谢!
Cleanser x = new Cleanser();
x.scrub();