In this section, you're going to learn about a very special member we can assign to our custom classes, that is, the constructor. To start off, let's take a look at the following code:
package gettingobjectoriented; import java.util.*; public class GettingObjectOriented { public static void main(String[] args) { Scanner reader = new Scanner(System.in); Person john = new Person(); john.firstName = "John"; john.lastName = "Doe"; john.birthday = new GregorianCalendar(1988,1,5); System.out.println( "Hello my name is " + john.fullName() + ". I am " + john.age(new GregorianCalendar()) + " years old."); } }
This program creates an instance of our custom class Person and immediately assigns some values to member variables of ...