Results 1 to 6 of 6

Thread: [Resolved] Inheritance question ...

Threaded View

  1. #1

    Thread Starter
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    [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?

    .
    Last edited by honeybee; Oct 16th, 2001 at 07:36 AM.
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width