[Resolved] Inheritance question ...
If I decide to subclass the Frame class, and then write code like this:
Code:
//All the necessary import statements here
public class frm extends Frame implements WindowListener
{ frm()
{ super("My Frame");
}
public void windowClosed(blah blah)
{}
//further blah blah to override the WindowListener methods
}
And in my applet I write this:
Code:
//All necessary import statements
public class MyApplet extends Applet
{ Frame f;
public void init()
{ f = new frm();
}
//some more blah blah
}
In the applet code, I am declaring a reference to the Frame class, which is parent to the frm class. But when I instantiate it, I am creating a new object of the frm class and not the Frame class. Is this allowed?
We were taught this yesterday, the teacher says it works OK, and I have yet to test it out. The teacher said it works because the child class frm does not have its own public methods, so its public interface is not different from the parent Frame class.
Is the above code right? Can you use a parent class pointer to point to an object of the child class?
Also a little off the topic, does the Frame class implement WindowListener? I don't think so. If it does not, the overridden methods from the WindowListener interface in the frm class do constitute the public interface of the frm class, right? And that means the public interface of the frm class is different from that of the Frame class, because there are public void windowClosed and other methods in frm which are absent in Frame.
Can someone help me understand this?
.