Results 1 to 7 of 7
- 07-09-2010, 05:44 AM #1
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
Problems with Static toString() method
Please refer to the following screenshot.
public class Student {
public int StudentIdentificationNumber;
public String FirstName;
public String LastName;
public int CreditsSoFar;
public double GPA;
@Override
public String toString() {
return ("FIRST Name: " + FirstName + "\n"
+ "LAST Name: " + LastName + "\n" + "Creditsofar"
+ Integer.toString(CreditsSoFar)+"\n"
+ Double.toString(GPA)+"\n");
}
Whenever I do this there are red lines in the code below and IDE says tht it its an "illegal start of expression". could you Please explain how I can display the numerical values of the class in the toString() method.
- 07-09-2010, 05:49 AM #2
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Post exact error messages, and we can probably help you. Until then, noone can figure out what lines you are actually having trouble with. Makes it damn hard to figure out whats wrong -.-
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 07-09-2010, 09:18 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,448
- Rep Power
- 16
For starters that's not a static method, so the thread title's wrong.
- 07-09-2010, 09:30 AM #4
- 07-09-2010, 09:39 AM #5
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
I am trying to paste a screenshot of the IDE so that I can show the error message shown in the IDE. It is simple but it is to me quite confusing.
- 07-09-2010, 10:10 AM #6
Member
- Join Date
- Jul 2010
- Posts
- 10
- Rep Power
- 0
The problem is deeper than this. I will Open a new thread that will include all the problems which will be more clearer in getting picture across.
- 07-09-2010, 10:15 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,395
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
non-static method getType cannot be referenced from a static contex
By Dekkon0 in forum New To JavaReplies: 4Last Post: 05-12-2010, 11:05 AM -
Java class HashIt with a static recursive method and a static iterative method
By kezkez in forum New To JavaReplies: 3Last Post: 02-09-2010, 05:22 AM -
toString() method
By 01allenh in forum New To JavaReplies: 2Last Post: 03-25-2009, 11:43 PM -
static method sparks error on overriding non-static method
By MuslimCoder in forum New To JavaReplies: 1Last Post: 02-10-2009, 10:03 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks