java设计一个日期及其测试类把日期类放在MyPackage,测试类和日期类不在同一包中
时间: 2023-05-30 20:06:59 浏览: 116
日期类:
```java
package MyPackage;
public class MyDate {
private int year;
private int month;
private int day;
public MyDate(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}
public void setYear(int year) {
this.year = year;
}
public void setMonth(int month) {
this.month = month;
}
public void setDay(int day) {
this.day = day;
}
@Override
public String toString() {
return year + "-" + month + "-" + day;
}
}
```
测试类:
```java
import MyPackage.MyDate;
public class TestMyDate {
public static void main(String[] args) {
MyDate date = new MyDate(2022, 12, 31);
System.out.println(date);
}
}
```
阅读全文