Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: keyword Extends

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default keyword Extends

     public class KeyWordExtends extends JFrame {
     
     
        public void bla () {
     
            setSize(400, 500);
            setVisible(true);
        }
     
        public static void main(String[] args) {
     
            KeyWordExtends extend = new KeyWordExtends();
            extend.bla();
        }
    }

    the class KeyWordExtends is a subclass of the JFrame?

    does it mean . that this class is an INSTANCE of the JFrame class?

    so thats why this class shows a JFrame window.....
    without declaring an object for the JFrame?


    and how bout this one

    public class NewClass extends JFrame {
     
        JFrame frame;
        JButton button;
        JPanel panel;
     
        public void sample() {
     
            frame = new JFrame("Sample");
     
            frame.setDefaultCloseOperation(NewClass.EXIT_ON_CLOSE); // is this a new class of the JFrame class?
            frame.setSize(500, 500);
            frame.setVisible(true);
            frame.getContentPane().add(panel);
        }
     
        public static void main(String[] args) {
     
            NewClass object = new NewClass();
     
            object.sample();
        }
    }

    NewClass is a new class for the JFrame class?, so it can access any static methods or fields of the JFrame class?
     frame.setDefaultCloseOperation(NewClass.EXIT_ON_CLOSE); // is this a new class of the JFrame class?
    Last edited by chronoz13; November 27th, 2009 at 04:32 AM.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: keyword Extends

    It has a base class of JFrame which has been extended, ie you have added custom functionality to the JFrame object. ALl methods from JFrame class are kept and used as normal, this is indeed why a window is still displayed.

    Chris

  3. The Following User Says Thank You to Freaky Chris For This Useful Post:

    chronoz13 (November 27th, 2009)

  4. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: keyword Extends


  5. The Following User Says Thank You to Json For This Useful Post:

    chronoz13 (November 27th, 2009)

  6. #4
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: keyword Extends

    so this is "Inheritance"..

Similar Threads

  1. How to highlight search keyword in text?
    By Mohd in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: February 1st, 2009, 06:35 AM