我的Java包中有四個類。只有一個類有main()
方法。從另一個類運行類的方法
當我運行main()
方法時,如何運行四個類中的所有方法?
這裏是我的課:
Cat1.java
package test;
public class Cat1 {
public Cat1() {
System.out.println("100");
}
public Cat1(int i){
i = 10;
System.out.println(" cat1 i :"+ i);
}
}
Cat2.java
package test;
public class Cat2 extends Cat1 {
public Cat2() {
System.out.println("200");
}
public Cat2(int i){
super();
System.out.println("Cat 2 ; "+ i);
}
}
Cat3.java
package test;
public class Cat3 extends Cat2{
public Cat3() {
System.out.println("300");
}
public Cat3(int i){
super();
System.out.println("Cat 3 : "+ i);
}
}
Sample.java
package test;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Locale;
public class Sample {
/**
* @param args
*/
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
//Date d = cal.getTime();
Locale locale = new Locale("en");
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
System.out.println(" LONg date : " + dateFormat.format(cal.getTime()));
String incomeData = "200,2,2,2,2";
int expense = 0;
String expenseSplit = incomeData;
System.out.println(" e");
String expenseArray[] = expenseSplit.split(",");
String income = expenseArray[0];
for (int i = 1; i < expenseArray.length; i++) {
expense = expense+Integer.parseInt(expenseArray[i]);
}
System.out.println(" Income "+ income);
System.out.println(" expense "+ expense);
}
}
你想究竟如何運行呢?從'main'方法開始順序? –
您在'Cat *'類中沒有任何方法。 –
@TAsk我同意 - 他們只是構造函數。 –