Results 1 to 6 of 6
- 02-24-2013, 09: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, 10:11 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
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 JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 02-24-2013, 10: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 10:24 PM.
-
Re: OverRide
- 02-24-2013, 11: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, 12:07 PM -
Cannot override PasteAction
By madroadbiker in forum Advanced JavaReplies: 8Last Post: 06-10-2011, 02:43 PM -
Is it necessary to override setValueAt
By pink123 in forum AWT / SwingReplies: 1Last Post: 03-23-2011, 01:17 AM -
@Override Annotation
By Unsub in forum New To JavaReplies: 2Last Post: 01-30-2010, 03:06 PM
Bookmarks