BubbleGum
BubbleGum

Reputation: 11

Getting the "cannot find symbol" error in a Java program

package testing;

public class Clerk {
    private String name;
    private double score;
    private Clerk clerk;
    
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public double getScore(){
        return score;
    }
    public void setscore(double score){
        this.score=score;
    }
    public Clerk(String name, double score){
        this.name=name;
        this.score=score;
    }
    public void Clerk(String name, double score){
        clerk.add(clerk); //i am getting the error here
        
    }
  

The error stated is "cannot find symbol". I am not sure what I'm doing wrong. Much help is appreciated.

Upvotes: 1

Views: 76

Answers (2)

Rinat
Rinat

Reputation: 380

There is no valid reason to name the method with the class name. As said here Methods With Same Name as Constructor - Why? it will be considered a bad practice. Try to rewrite your code like this:

public void setClerk(Clerk clerk){
    this.clerk = clerk;
}
public Clerk getClerk(){
    return clerk;
}

Upvotes: 1

Cristi B.
Cristi B.

Reputation: 681

There is no method add in that class Clerk. To make it compile add:

private void add(Clerk clerk) {
    //do something
}

Upvotes: 1

Related Questions