Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Imagine there is a class named Word which extends String. A Word is a specific sort of String, which includes only alphabetical characters and has

Imagine there is a class named Word which extends String. A Word is a specific sort
of String, which includes only alphabetical characters and has methods such as
getDefinition, getPartOfSpeech, and conjugate. Is there a problem with the following
method which, is meant to Override String's compareTo method?
@Override
public int compareTo(Word w)
{
String s1= this.toString();
String s2= w.toString();
return s1.compareTo(s2);
}
Yes, there's a problem. The method should take a String as input.
No problem. It is a valid compareTo
Yes, there's a problem. The method should return a boolean.
Yes, there's a problem. The method should cast this and w to String rather than
relying on toString methods.
I have a method:
public double importantDataChange(double x, double y)
And I need to make it so that while one thread is using the importantDataChange
method, no other threads can interact with the containing object. Which of the
following changes to the method header makes it so?
public synchronized double importantDataChange(double x, double y)
public double synchronized importantDataChange(double x, double y)
public double importantDataChange(double x, double y) implements
synchronized
None of the above because synchronized only acquires the lock for the method,
not the whole object.
image text in transcribed

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago