Results 1 to 6 of 6
- 02-24-2013, 08:36 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 10
- Rep Power
- 0
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
-
Re: OverRide
Only methods can be overridden, not variables.
- 02-24-2013, 09:11 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 657
- Rep Power
- 1
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.
JimThe Java™ Tutorial
YAT -- Yet Another Typo
- 02-24-2013, 09:22 PM #4
Member
- Join Date
- Feb 2013
- Posts
- 10
- Rep Power
- 0
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 09:24 PM.
-
Re: OverRide
- 02-24-2013, 10:37 PM #6
Member
- Join Date
- Feb 2013
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
A question on @Override
By fatabass in forum New To JavaReplies: 9Last Post: 02-02-2012, 11:07 AM -
Cannot override PasteAction
By madroadbiker in forum Advanced JavaReplies: 8Last Post: 06-10-2011, 01:43 PM -
Is it necessary to override setValueAt
By pink123 in forum AWT / SwingReplies: 1Last Post: 03-23-2011, 12:17 AM -
@Override Annotation
By Unsub in forum New To JavaReplies: 2Last Post: 01-30-2010, 02:06 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks