Results 1 to 4 of 4
Thread: overriding toString method
- 06-01-2010, 04:07 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 8
- Rep Power
- 0
overriding toString method
Hi
this is my code but when I run it with netbeans it will show just this line instead of my array!!
the line:run:
BUILD SUCCESSFUL (total time: 0 seconds)
and my class is this:
Java Code:public class Score { public final static int maxSize = 10; protected int size; protected GameEntry[] entries; public Score() { size = 0; entries = new GameEntry[maxSize]; } public void add(GameEntry e,int b){ entries[b] = e; } @Override public String toString() { String s = "["; for (int i = 0; i < size; i++) { if (i > 0) { s += entries[i]; } s += ","; } return s; } public static void main(String[] args){ Score x = new Score(); GameEntry v = new GameEntry("neda", 12); GameEntry g = new GameEntry("nima", 18); x.add(v, 0); x.add(g, 1); x.toString(); } }
thanks!!
Mod Edit: code tags addedLast edited by Fubarable; 06-01-2010 at 04:17 AM. Reason: mod edit: code tags added
-
I hope you don't mind that I added code tags to your post. To learn to do this yourself, please see the link in my signature below.
anyway to show your String, how about having
as the last line of your main method so that the String created by x is displayed.Java Code:System.out.println(x);
- 06-01-2010, 04:29 AM #3
Member
- Join Date
- Jun 2010
- Posts
- 8
- Rep Power
- 0
thanks!! but it just return : "[" !!!!!!!
- 06-01-2010, 04:35 AM #4
Member
- Join Date
- Jun 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Overriding equals method
By sky in forum New To JavaReplies: 7Last Post: 03-12-2010, 03:39 PM -
Method Overriding - Seriously confused :-(
By fullmetaljacket in forum New To JavaReplies: 4Last Post: 05-26-2009, 04:18 PM -
[SOLVED] Method Overriding
By MithunDhar in forum New To JavaReplies: 3Last Post: 04-06-2009, 08:02 AM -
Overriding a method of a JPanel which was visually added to a container
By Pucho in forum NetBeansReplies: 1Last Post: 04-01-2009, 02:00 AM -
is overriding static method possible
By raghu in forum Advanced JavaReplies: 1Last Post: 01-22-2008, 12:38 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks