Results 1 to 4 of 4
  1. #1
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default has-a relationship

    Java Code:
    class E{}
     
    class P extends E{}
     
    class B{}
     
    Class G extends B {private P p;}

    G has-a E, is it correct?

    Many Thanks!

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: has-a relationship

    Yep, because a P is a E and G has a P, G also has a E.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    wayenng is offline Member
    Join Date
    Dec 2012
    Posts
    35
    Rep Power
    0

    Default Re: has-a relationship

    Quote Originally Posted by JosAH View Post
    Yep, because a P is a E and G has a P, G also has a E.

    kind regards,

    Jos


    Thanks Jos!

    But it doesn't need to process casting anymore?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: has-a relationship

    Quote Originally Posted by wayenng View Post
    But it doesn't need to process casting anymore?
    Nope, 'up casts', e.g. from P to E, are never necessary, because a derived class is a base class. 'down casts', e.g. from E to P always have to be explicit (who knows if your Animal class is actually an Aardvark class? ;-)

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. What is a happens-before relationship?
    By johnmerlino in forum New To Java
    Replies: 1
    Last Post: 06-15-2014, 08:57 AM
  2. relationship between classes
    By talia in forum New To Java
    Replies: 1
    Last Post: 12-10-2011, 03:33 PM
  3. help with mapping and relationship
    By peace76 in forum Enterprise JavaBeans (EJB)
    Replies: 5
    Last Post: 12-07-2010, 07:12 PM
  4. class relationship
    By RajShri in forum New To Java
    Replies: 2
    Last Post: 01-04-2010, 05:54 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
  •