Program - getting error cannot find symbol

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cazconv2007
    New Member
    • Feb 2007
    • 30

    Program - getting error cannot find symbol

    i cant understand why it says cannot find symbol can you guys look thanx
    i can get it to show john doe but not my next name.

    class Name
    {

    public String firstName ="carl";
    private String lastName = "Johnson";

    public Name( String first ,String last)
    {
    firstName = first;
    lastName = last;
    }

    void setFirstName(St ring first)
    {
    firstName = first;
    }
    public String getFirstName()
    {
    return firstName;
    }

    public String getLastName()
    {
    return lastName;
    }

    public String toString()
    {
    return "Name" + lastName + "," + firstName;
    }


    }

    public class NameDriver
    {
    public static void main(String args[])
    {
    Name names = new Name("John", "Doe");
    Name names1 = new Name ();
    System.out.prin tln (names.getFirst Name());
    System.out.prin tln (names);
    System.out.prin tln (names1.getFirs tName());

    }



    }
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    this requires a constructor with no parameters
    Code:
         Name names1 = new Name ();
    e.g.
    Code:
    public Name( )
    {
    firstName = "no";
    lastName = "name";
    }

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by cazconv2007
      i cant understand why it says cannot find symbol can you guys look thanx
      i can get it to show john doe but not my next name.

      class Name
      {

      public String firstName ="carl";
      private String lastName = "Johnson";

      public Name( String first ,String last)
      {
      firstName = first;
      lastName = last;
      }

      void setFirstName(St ring first)
      {
      firstName = first;
      }
      public String getFirstName()
      {
      return firstName;
      }

      public String getLastName()
      {
      return lastName;
      }

      public String toString()
      {
      return "Name" + lastName + "," + firstName;
      }


      }

      public class NameDriver
      {
      public static void main(String args[])
      {
      Name names = new Name("John", "Doe");
      Name names1 = new Name ();
      System.out.prin tln (names.getFirst Name());
      System.out.prin tln (names);
      System.out.prin tln (names1.getFirs tName());

      }



      }
      You have a constructor
      Code:
       public Name( String first ,String last)
      so the default no-args constructor is not automatically created for you by the compiler therefore you can't call the no-arg constructor as it is not there. Have a read at this.

      Comment

      Working...