问题又来了
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的聊天程序怎么实现在线用户列表?~
- SWT问题求助
- 怎样写这个方法???
- 请教?:一个长度为20的字符串转换为长整型出现异常
- 如何作出CSDN论坛上的这种树形结构啊,求教各位大侠了!
- 急救,我编写一些代码,但编绎时老提示出错。请大虾们帮忙解决。。。。。。。
- 求助~如何在socket不断的情况下,收发16进制的数据?
- 几个出错信息,请大家帮忙友情解决(我没分了)
- 如何打开jpanel???????、、、在线等待!!!!
- 什么时代外数据?
- 急急急,壓縮 有中文名的文件 後 在壓縮文件中無法正常顯示中文 文件名 幫忙看一下
- 今天冬至,散分.还有希望考试不要挂科!!!在问一个<接口>问题~~~~
多态,调用的是运行时的类型的方法,子类覆盖了父类的,当然调用子类的。 Cleanser.main(args); //??这里为什么不能用super.main(args),还有参数args是什么意
静态方法怎么用super?
args是命令行参数
多态,调用的是运行时的类型的方法,子类覆盖了父类的,当然调用子类的。
------------------------------------------------------------------
如果我想调用Cleanser.scrub()改怎么做?
谢谢!
Cleanser x = new Cleanser();
x.scrub();