Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago