Question: 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.
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 float value: private float weight: public void setValue (final f1oat value) ( this. value value:) public float getValue O ( return value:) public float getWeightO ( return weight:1 public Coin(final float value, final float weight) ( this. valuevalue: this. welcht weight: public boolean equals (final Object that) ( return (that instanceof Coin) & (this. getValueO (Coin) that). getValue )) a) 0.5 TRUE or FALSE (circle one)? The equals method does not care about the weight of the coin value. because coins are compared based on their face b) 1 Given the above Coin class, what is the output of the following code? final Coin nl new Coin(0. 05f, 5. 0F): final Co in n2-nov Coin(0.05f. 5.1f): System. out. printin(nl. equals (n2) + (n n2)): // ansver here> n2. setValue (0. 10f): System.out. printinnl, equals (n2)Gal 2)); / ansver here -> e) 1 Given the above Coin class, what is the output of the following code? final Coin ni new Coin (0.05f, 5.or): final Coin n2nl; Systen.out, printin(nl. equals (n2) + " " + (n1 n2)); // answer here n2. setValue (0. 100): System. out. printin(nl. equals (n2)(aln2));/ answer here -> d) 0.5 Given the above Coin class, what is the output of the following code? final Coin nl -new Coin(0. 05f, 5.0r): System, out, printin (nl, equals (".05")); // answer here-> System. out. printIn (nl. equals (Float. valueor (0. 05))); // answer here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
