Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Final exam review Spring2007:Understanding inheritance

Back to Final Review-Spring 2007

Questions? Answers? Comments?


> Superhero batman = new Superhero(); would just work, no output?
> Superhero leo = new NinjaTurtle(0); would also work, no output
> leo.introduce(); —-> "I'm Leonardo"
> batman.introduce(); —-> "Hello. I am Batman. And I am weak"

When you create a method in a subclass that overrides a method from the superclass, how do you invoke the superclass method's behavior? What constraints are there for doing this in a constructor of a subclass?......

Wouldn't you just cast 'this' to the superclass? What are the constraints??


Question: So if you had 'public class Agent extends Turtle, and inside of that class there's a method like this:
public Agent (int x, int y, ModelDisplay modelDisplayer, Simulation thisSim) {
    // let the parent constructor handle it
    super(x,y,modelDisplayer);
    init(thisSim);
  }
..... is the parent constructor in this case the one inside of Turtle? and by using super, you're allowing the method inside of Turtle to handle it? or vice versa??|

Question: for the rewriting of the DrawableNode class question, since LLNode can do everything DrawableNode can, wouldn't you just need this?:
public class DrawableNode extends LLNode{
  }


Understanding Inheritance
I got this answer for the line—- leo.introduce();
Hello. I am Leonardo. And I am strong.
batman.introduce();
Hello. I am Batman. And I am weak.

Is this correct?? Am I assuming correctly that the object leo will use the constructor in the NinjaTurtle class, but it will use the method introduce() from the Superhero class?

I think that leo.introduce() uses the introduce method from the ninja turtle class because of dynamic binding

Modifications made to DrawableNode class:

public class DrawableNode extends LLNode{
public DrawableNode(){
super();
}
}

is that right? we have to take out the global variable, public DrawableNode next, too, correct?

For the inheritance you don't need the quotes (i think)
I'm Leonardo
Hello. I am Batman. And I am weak.

What constraints are there for doing this in a constructor of a subclass?...... Having the same constructor in the subclass, makes it basically the same thing as its superclass?? help!




Link to this Page