Computers and Technology

Consider the following Java class. Recall that x instanceof C tells you whether the dynamic type of x is C or a subtype of C.
class Coin {
private double value;
private double weight;
public void setValue(final double value) { this. value = value; }
public double getValue() { return value; }
public double getWeight() { return weight; }
public Coin(final double value, final double weight) {
this. value = value;
this. weight = weight;
}
public boolean equals(final Object that) {
return (that instanceof Coin) &&
(this. weight == ((Coin) that).weight);
}
}
a) TRUE or FALSE: The equals method does not care about the weight of the coin because coins are compared based on their face value.
b) Given the above Coin class, what is the output of the following code?
final Coin n1 = new Coin(0.05, 5.0);
final Coin n2 = new Coin(0.05, 5.1);
System. out. println(n1.equals(n2) + " " + (n1 == n2));
// answer here ->
n2.setWeight(5.0);
System. out. println(n1.equals(n2) + " " + (n1 == n2)); ));

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, abbygriffin2009
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
image
Computers and Technology, 22.06.2019 22:00, lgary9462
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass. cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array. c . run this program and observe the results.
Answers: 1
image
Computers and Technology, 23.06.2019 19:00, nayo2006
Acompany is hiring professionals for web designing. the firm is small with few resources. they want employees who possess problem-solving skills and can independently carry out responsibilities. which kind of employee should they select?
Answers: 2
image
Computers and Technology, 24.06.2019 13:00, sparkyjones02
Which best describes the condition under which the unicode output is the same as plain text ?
Answers: 1
Do you know the correct answer?
Consider the following Java class. Recall that x instanceof C tells you whether the dynamic type of...

Questions in other subjects:

Konu
Mathematics, 25.01.2021 23:40
Konu
Mathematics, 25.01.2021 23:40
Konu
Chemistry, 25.01.2021 23:40
Konu
Mathematics, 25.01.2021 23:40