| ||||||||||
I won't ask you to DRAW a complicated UML diagram, but questions like these are fair game. "#" means "Protected" – not public nor private. Mark Guzdial |
A is right. B – trace it out. Presume that all instance variables are public to start with, and don't worry about casting. this.simulation.factory. Now, figure out casting. C. How about this.simulation.agents as a start? D is right. Mark Guzdial |
If you squint really hard and hold the UML diagram about 10 feet away, it vaguely starts to look like Abraham Lincoln. Or maybe that's King REMOVEDng. I forget. Mark Guzdial |
Actually, (b) isn't quite right. It's got to be of the form ((CAST)(THING TO CAST)).THINGTOACCESS. So it should be ((FactorySimulation)(this.Simulation)).getFactory() (missing one right paren in Krista's). Mark Guzdial |
Good questions, Kyle! In this.simulation.getAgents() (note: simulation not Simulation–you're not referring to the class, you're referring to an instance variable inherited by this), you are access a method getAgents() this is known to Simulation, and that's what the variable simulation is declared as. Does that answer your second question, too, Kyle? There is no instance variable FactorySimulation, so that wouldn't work. Mark Guzdial |