I need some help in implementing deep copy constructor and not using the clone method. I understand that in order for the deep copy to work, you are making a copy of the object and not just the address pointing to that object. Otherwise if you make changes to one the original object will also observe the change. However, I am having problem with putting it into practice.
* This is the main method.
* It creates a Team object and then tests the copy constructor.
public static void main(String args)
Team team1 = new Team("The Java Studs", "Bill", "Ted", "Carol", "Alice",
new Competition("ACM Programming Contest","The Java Studs", "Team University Java", 2008),
new Competition("Antarctic Programming Contest","The Java Studs", "Frigid South", 2010) );
Team team2 = new Team(team1); // Copy constructor
// Change competition information for team2
team2.getCompetition1().setRunnerup("Java By Night Java By Day");
// Output information for both team1 and team2.
// Team1's should be unchanged from the original values.
This is my output from command line when I try to run it.Code:
* Team copy constructor; Performs a deep copy from the Competition class
* instead of just copying a reference to the same Competition objects.
public Team(Team otherTeam)
Team copyTeam = new Team();
Exception in thread "main" java.lang.NullPointerException