Search code examples
javaobjectgetter-setter

Error in set methods for object


Not quite sure why, but eclipse is putting an error on my setter methods that reads "Syntax error, insert "...VariableDeclaratoid" to complete FormalParamaterList."

Here's my code:

public class Student {
    public int id;
    public String name;

    Student() {

    }

    public int getID() {
        return id;
    }


    public void setID(i) {
        this.id = i;
    }

    public String getName() {
        return name;
    }

    public void setName(n) {
        this.name = n;
    }

    public String toString() {
        System.out.println("The student's name is: " + this.name);
        System.out.println("The student's ID is: " + this.id);
    }
}

Solution

  • Because you did not give your parameter i and n their types. See below

    public void setID(int i) {
       this.id = i;
    }
    
    
    
    public void setName(String n) {
      this.name = n;
    }