Which statement sets the name of the Hat instance?

View the Exhibit.
<code>
public class Hat {
public int ID =0;
public String name = “hat”;
public String size = “One Size Fit All”;
public String color=””;
public String getName() { return name; }
public void setName(String name) {
this.name = name;
}
</code>
Given:
<code>
public class TestHat {
public static void main(String[] args) {
Hat blackCowboyHat = new Hat();
}
</code>
Which statement sets the name of the Hat instance?

View the Exhibit.

public class Hat {
public int ID =0;
public String name = "hat";
public String size = "One Size Fit All";
public String color="";
public String getName() { return name; }
public void setName(String name) {
this.name = name;
}

Given:

public class TestHat {
public static void main(String[] args) {
Hat blackCowboyHat = new Hat();
}

Which statement sets the name of the Hat instance?

A.
blackCowboyHat.setName = “Cowboy Hat”;

B.
setName(“Cowboy Hat”);

C.
Hat.setName(“Cowboy Hat”);

D.
blackCowboyHat.setName(“Cowboy Hat”);



Leave a Reply 0

Your email address will not be published. Required fields are marked *