Objects as function parameters and returned results - Java Object Oriented Design

Java examples for Object Oriented Design:Method

Description

Objects as function parameters and returned results

Demo Code

class Date {
  int dd;/*from w w w.  j a v  a  2 s  .c o  m*/
  int mm;
  int yyyy;

  static final String[] months = { "January", "February", "March", "April", "May", "June", "July", "August",
      "September", "October", "November", "December" };

  // Constructor
  Date(int day, int month, int year) {
    this.dd = day;
    this.mm = month;
    this.yyyy = year;
  }

}

public class Main {

  static void Display(Date day) {
    System.out.println("Date:" + day.dd + "/" + day.mm + "/" + day.yyyy);
  }

  public static void main(String[] args) {

    Date day1 = new Date(23, 12, 1971);
    Display(day1);
    day1.mm = 6;
    Display(day1);
    System.out.println(day1);
  }
}

Related Tutorials