Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Is this method a mutator or accessor method? without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I have the below method which returns true if a growth rate is less than 0 or false otherwise. I was wondering what kind of method it would be, mutator or accessor.
public boolean endangered(double GR) { if (GR < 0) { return true; } else { return false; } }
It does not access or mutate any value — its a new value that is being returned, it seems, and will possibly be used somewhere.
Below is the full class, if that helps:
public class Species { private int population; private double growthRATE; private String speciesName; private String endangered; public Species() { speciesName = "Dingo"; population = 1000; growthRATE = 0.6; } public Species(String name, int population, double GR) { name = name; population = population; growthRATE = GR; } //Mutator methods //accessor methods public boolean endangered(double GR) { if (GR < 0) { return GR < 0; } else { return GR < 0; } } }
Answer
None of them. You doesn’t mutate any instance and you don’t return a field instance either.
Your method makes some logic, so you could say that it is a logic/business method.
We are here to answer your question about Is this method a mutator or accessor method? - If you find the proper solution, please don't forgot to share this with your team members.