New to Java Need help with constructors
Someone let me know where im going wrong. I need basic examples please :) .
Heres my code.
public class Grades
{
String ssn;
String name;
String grade;
Grades(String s, String n, String g)
{
ssn = s;
name = n;
grade = g;
}
}
class Student{
public static void main(String args[])
{
Grades John = new Grades(351-63-2182, John, A);
Grades Kris = new Grades(432-35-2562, Kris, B);
System.out.println(John + " " + Kris);
}
}
When i attempt to compile this code i get an error. Any help possible would be much appreciated.
Thanks!
[676 byte] By [
XQUIZITxJE] at [2007-11-11 8:07:12]

# 1 Re: New to Java Need help with constructors
Your constructor accepts three Strings. You're passing in 351-63-2182, John, A. You probably mean to pass in "351-63-2182", "John", "A".
Also, note that when printing objects (when you do System.out.println(John + " " + Chris);) it will convert them to Strings using their toString() method. Since you have not overrid the toString() method, it will use the toString() method from the object class, which prints memory.
destin at 2007-11-11 22:36:28 >
