-3
假设我有一个CommonClass
类,显示的是通用于所有其他类文件:Java的面向对象的定义在一个共同的方法定义一个特定的方法定义
public class CommonClass {
public static void displayFoo() {
... // printlns here
displaySpecific(); // Among all files made common by this method, I
// want to display something different among the other files
... // printlns here
}
}
我打算叫,像这样:
// Filename: fileA.java
public class FileA {
public static void myFunc() {
CommonClass.displayFoo();
// however, I should have a specific definition
// for the displaySpecific()
// method. Should I use interfaces? How should it be structured.
}
// displaySpecific method here
}
另一个文件:
// Filename: fileB.java
public class FileB {
public static void myFunc() {
CommonClass.displayFoo();
// however, I should have a specific definition
// for the displaySpecific()
// method. Should I use interfaces? How should it be structured.
}
// displaySpecific method here
}
等等...
主要可能是这...
public class MyMain {
public static void main(String[] args) {
FilaA.myfunc();
System.out.println("");
FileB.myfunc();
System.out.println("");
... and so on...
}
}
这是预期输出:
Common String Common String Common Common Common Common Common
Common Common Common Common Common Common Common
This is File A
Common String Common String Common Common Common Common Common
Common Common Common Common Common Common Common
Common String Common String Common Common Common Common Common
Common Common Common Common Common Common Common
This is File B
Common String Common String Common Common Common Common Common
Common Common Common Common Common Common Common
我应该怎么办呢?
而你的问题是...? –
问题编辑..对不起,如果不清楚。 –
为什么要静态函数? – home