Java Reference
In-Depth Information
Problem
One of your classes requires the use of another class's functionality. However, no other
class requires the use of that same functionality. Rather than creating a separate class
that includes this additional functionality, you'd like to generate an implementation that
can only be used by the class that needs it, while placing the code in a logical location.
Solution
Create an inner class within the class that requires its functionality.
import java.util.ArrayList;
import java.util.List;
/**
* Inner class example. This example demonstrates how
a team object could be
* built using an inner class object.
*
* @author juneau
*/
public class TeamInner {
private Player player;
private List<Player> playerList;
private int size = 4;
/**
* Inner class representing a Player object
*/
class Player {
private String firstName = null;
private String lastName = null;
private String position = null;
private int status = -1;
Search WWH ::




Custom Search