集册 Java实例教程 使用构造函数方法存储日期的类

使用构造函数方法存储日期的类

欢马劈雪     最近更新时间:2020-01-02 10:19:05

634
使用构造函数方法存储日期的类

class Date {

  int dd;/** from nowjava.com**/

  int mm;

  int yyyy;


  // Constructor (method)

  public Date(int day, int month, int year) {

    this.dd = day;

    this.mm = month;

    this.yyyy = year;

  }


}


public class Main {

  static boolean isEqual(Date d1, Date d2) {// 来 自 n o w  j a v a  . c o m

    return (d1.dd == d2.dd && d1.mm == d2.mm & d1.yyyy == d2.yyyy);

  }


  public static void main(String[] args) {

    Date day=new Date(23,12,1971);

    System.out.println("Date:"+day.dd+"/"+day.mm+"/"+day.yyyy);


    Date day1 = new Date(23, 12, 1971);

    Date day2 = day1; // beware not copying here: shallow copying
展开阅读全文