DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2006

    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.


  2. #2
    Join Date
    Dec 2005
    New Jersey
    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.

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 03:16 PM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  4. Replies: 0
    Last Post: 01-31-2002, 11:08 PM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.