Skip to content

overriding equals() method in java #21390

Answered by Wabri
kateryna216 asked this question in General
Discussion options

You must be logged in to vote

Hi @kateryna216,

Welcome to the Github Community Forum!

The getName() method is declared in the parent Animal class, so with this in mind what access modifiers did you assign to getName()? If is a private method you can use that only in a Animal object. To use only in a ereditary class you can assign a protected modifiers. To use everywhere assign the public modifier.

Private method

private String getName() {
            return "something";
}

Protected method

protected String getName() {
            return "something";
}

Public method

public String getName() {
            return "something";
}

Hope to solve your problem :slight_smile:

-Gabriele-

Mark helpful posts with Accept as Solut…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants