Skip to content

Latest commit

 

History

History
executable file
·
19 lines (13 loc) · 1.19 KB

1171.md

File metadata and controls

executable file
·
19 lines (13 loc) · 1.19 KB

Back to questions

Solution to 1171: Cloning graphs

See code at solutions/code/tutorialquestions/question1171

The question was broken down into steps and accompanied by various hints. Look back at these steps and hints, and see how the questions have been implemented in the sample source code solutions. Here are just a few further notes:

The implications of making a bitwise identical copy of an object are that an object reference field will refer to the same object in both the original and copied object. In the copy, object references will not refer to fresh objects that have themselves been cloned.

GraphNode<E> inherits its clone method from Object. The method is protected, thus it is only visible to subclasses of GraphNode<E>, or to classes inside the java.lang package (the package of Object). Because your main is in a class separate from GraphNode<E>, and not in the java.lang package, the call to clone does not compile. Note that when clone was called from method foo inside GraphNode<E> this was OK, because the protected method clone in superclass Object is visible to methods in the subclass GraphNode<E>.