Created
January 11, 2017 00:48
-
-
Save drnickallgood/a67682fa3ac30a964154d63a1625375c to your computer and use it in GitHub Desktop.
Person Java Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Person.java | |
class Person { | |
//Static variable for counting Person instances | |
private static int idCount = 0; | |
//Instance variables | |
private Name name; | |
private int id; | |
//Constructor initializing instance variables with supplied names | |
public Person(String firstName, String lastName) { | |
name = new Name(firstName, lastName); | |
id = ++idCount; | |
} | |
//Present a Person object as a string | |
public String toString() { | |
return "\n\tId: " + id + name; | |
} | |
//Display the data of a Person object | |
public void display() { | |
System.out.println("<<Person>>>" + this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment