class or interface expected error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ngeywa
    New Member
    • Sep 2010
    • 1

    class or interface expected error

    I am new in java and need your assistance. i have the code below which keep throwing error "class or interface expected".

    Code:
    public class Candidates
    {
    String candidateName;
    String candidateAddress;
    String candidatePosition;
    
      public candidate()
      {
        candidateName = "Peter";
        candidateAddress = "Aburi";
        candidatePosition = "Driver";
      }
    
      public void display()
      {
        System.out.printIn ("Name"+ candidateName);
        System.out.printIn ("Address"+ candidateAddress);
        System.out.printIn ("Position"+ candidatePosition);
      }
        public static void main (String arg [])
         {
           candidate can = new candidate();
           can.display();
          }
    
    }
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Hi!
    In the first line, you called your class "Candidates ", but the constructor is for a class called "candidate" and in the main function you try to create an object of the type "candidate" . You should have the same name at all of these places and traditionally the file should have the same name (with a .java at the end of course).

    Greetings,
    Nepomuk

    Comment

    • xploreraj
      New Member
      • Jan 2010
      • 49

      #3
      Hi ngeywa,
      Nepomuk is true.
      The name of the class "Constructo rs" (refer line 1) and the name of the constructor (refer line 7) must be exactly same, and you also need to modify line 22 in the same regard.

      Regards,
      xploreraj

      Comment

      Working...