Results 1 to 2 of 2
  1. #1
    N00Bie is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Initialize Vs extends

    Hi,
    I'm a bit confused...

    If you can simply add a "extends X" keyword on top to get access to all of the other classes variables and methods

    why do the
    TheClass x = new TheClass();
    x.something();

    etc?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    extends defines identity, also known as an is-A relationship.
    You do the other thing (also known as composition) when you just want the behaviour without changing the type of the guy providing the behaviour.

    Generally, it is easier to acquire/change behaviour than it is to change identity.

Similar Threads

  1. Advanced extends and implements
    By V1C3M4N in forum Advanced Java
    Replies: 15
    Last Post: 11-17-2010, 02:28 PM
  2. Class that extends JFrame help
    By javaman1 in forum New To Java
    Replies: 5
    Last Post: 11-10-2010, 03:29 AM
  3. servlet extends ..web server?
    By waqar100 in forum Java Servlet
    Replies: 5
    Last Post: 06-08-2010, 06:18 AM
  4. extends question
    By mac in forum New To Java
    Replies: 8
    Last Post: 04-03-2010, 03:29 AM
  5. My icon extends my JButton
    By hitmen in forum AWT / Swing
    Replies: 5
    Last Post: 03-06-2009, 08:49 AM

Posting Permissions

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