Start New Discussion within our Software Development Community

When I debug this method, I can clearly see that currentNode = Workstation, so I am puzzled as to why I'm still entering into the "Node" buffer print, rather than the "Workstation" buffer print. Shouldn't polymorphism handle this for me?:


part of Node Class

public void printToBufferAsHTML(Network network, StringBuffer buf) {
	
		buf.append("<HTML>\n<HEAD>\n<TITLE>LAN Simulation</TITLE>\n</HEAD>\n<BODY>\n<H1>LAN SIMULATION</H1>");
		Node currentNode = this;
		buf.append("\n\n<UL>");
		do {
			buf.append("\n\t<LI> ");

			if (isValidNode(currentNode))
				currentNode.printNodeToBufferAsHTML(buf, currentNode);
			else
				buf.append("(Unexpected)");

			buf.append(" </LI>");
			
			currentNode = currentNode.nextNode;
		} while (network.notCompleteCycle(currentNode));
		buf.append("\n\t<LI>...</LI>\n</UL>\n\n</BODY>\n</HTML>\n");
	}


private void printNodeToBufferAsHTML(StringBuffer buf, Node currentNode) {
		buf.append("Node ");
		buf.append(currentNode.name);
		buf.append(" [Node]");
	}
public class Workstation extends Node{
	
	public Workstation(String _name) {
		super(_name);
	}

	public Workstation(String _name, Node _nextNode) {
		super(_name, _nextNode);
	}
	
	public void printNodeToBufferAsHTML(StringBuffer buf, Node currentNode) {
		buf.append("Workstation ");
		buf.append(currentNode.name);
		buf.append(" [Workstation]");
	}
}

Whoops - forgot the level of access had to match also (private vs. public). Marking as solved. :)

This question has already been answered. Start a new discussion instead.