关于main函数的一个语法
这是父类:
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();
}
}
这是子类;
public class Detergent extends Cleanser
{
// Change a method:
public void scrub()
{
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();
x.foam();
x.print();
System.out.println( "Testing base class: ");
Cleanser.main(args);
}
} ///:~
子类的最后一句
Cleanser.main(args);
这个怎么理解阿~?
------解决方案--------------------public static void main(String[] args)
{
Detergent x = new Detergent();
x.dilute();
x.apply();
x.scrub();
x.foam();
x.print();
System.out.println( "Testing base class: ");
Cleanser.main(args);
不是有调用
dilute();
apply();
scrub();
foam();
print();
这几个方法么
最后Cleanser.main(args);调用父类的静态main方法
------解决方案--------------------调用父类的main方法啊.因为main方法为static,
所以可以直接用类名.方法调用.