Skip to content

Instantly share code, notes, and snippets.

@drnickallgood
Created January 11, 2017 00:48
Show Gist options
  • Save drnickallgood/a67682fa3ac30a964154d63a1625375c to your computer and use it in GitHub Desktop.
Save drnickallgood/a67682fa3ac30a964154d63a1625375c to your computer and use it in GitHub Desktop.
Person Java Class
//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