2005-11-21

Defining Classes

package exercise1;
public class newyearmain
{
public static void main(String[] args)
{
newyear date1= new newyear();
//挪出記憶體存放 date1
System.out.println("The new year is: ");
date1.makeItNewYears();
date1.writeOutput();

}

}
-----------------------------------------------
package exercise1;
//剛剛少package,所以一直有errors
public class newyear
{
public int month;
public int day;
public int year;
//method1:write output
public void writeOutput()
{
System.out.println(year+"/"+month+"/"+day);
}
//method2:make it new year
public void makeItNewYears()
{
month=1;
day=1;
year=2007;
}
}

0 Comments:

張貼留言

<< Home