Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By jim829
  • 1 Post By Fubarable

Thread: OverRide

  1. #1
    yanivdan98 is offline Member
    Join Date
    Feb 2013
    Posts
    10
    Rep Power
    0

    Default OverRide

    hi

    i run the code which wrote here..

    and it print for me "shape" and i dont understand why?

    someone can help me and explain me why "shape" is print and not "sqaure" ?

    thanks alot



    Uploaded with ImageShack.us

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,030
    Rep Power
    6

    Default Re: OverRide

    First, it would be helpful if you would include your code in text surrounded by [code][/code] tags.

    You didn't override show in the Square class so it called the method in Shape and used the value of str there. Also, realize that the instance field str in Shape and the instance field str in Square are two distinct fields and have nothing to do with each other.

    Jim
    yanivdan98 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    yanivdan98 is offline Member
    Join Date
    Feb 2013
    Posts
    10
    Rep Power
    0

    Default Re: OverRide

    thanks both,

    however i dont understand something,

    the str variable doesnt overrided? why not?

    if i had a overrided show method in sqaure with "return str" , it will return "sqaure" string?
    Last edited by yanivdan98; 02-24-2013 at 10:24 PM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: OverRide

    Quote Originally Posted by yanivdan98 View Post
    thanks both,

    however i dont understand something,

    the str variable doesnt overrided? why not?
    Again, in Java variables do not get overridden, only methods do. That is how Java is defined.

    if i had a overrided show method in sqaure with "return str" , it will return "sqaure" string?
    Yep.
    yanivdan98 likes this.

  6. #6
    yanivdan98 is offline Member
    Join Date
    Feb 2013
    Posts
    10
    Rep Power
    0

Similar Threads

  1. A question on @Override
    By fatabass in forum New To Java
    Replies: 9
    Last Post: 02-02-2012, 12:07 PM
  2. Cannot override PasteAction
    By madroadbiker in forum Advanced Java
    Replies: 8
    Last Post: 06-10-2011, 02:43 PM
  3. Is it necessary to override setValueAt
    By pink123 in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2011, 01:17 AM
  4. @Override Annotation
    By Unsub in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 03:06 PM

Posting Permissions

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