146k views
4 votes
An instance variable name of type String, initialized to the empty String. An instance variable score of type int, initialized to zero. A method called setName that has one parameter, whose value it assigns to the instance variable name. A method called setScore that has one parameter, whose value it assigns to the instance variable score. A method called getName that has no parameters and that returns the value of the instance variable name. A method called getScore that has no parameters and that returns the value of the instance variable score.

1 Answer

4 votes

Answer:

public class Class {

private String name ="";

private int score = 0;

//Method SetName

public void setName(String newName){

name = newName;

}

//Method SetScore

public void setScore(int newScore){

score = newScore;

}

//Method GetName

public String getName() {

return name;

}

//Method GetScore

public int getScore() {

return score;

}

}

Step-by-step explanation:

  • The class called Class is implemented in Java programming language
  • It has two fields (instance variables name and score)
  • Methods for setting the values of variables (mutator methods) or setters
  • Methods for getting the values of the variables (accessor methods) getters
User Kristian Svensson
by
3.6k points