0

Guys could you help explain me the last 2 lines please

MenBook mbobject = (MenBook) other

does it mean that mbobject is an object of the class Menbook? and what does the Other mean?

  public boolean moreExpensiveThan(Object other) {
  If(other == null)
    return false;
   else if (getClass() != other.getClass()) 
    return false;
   else {   MenBook mbobject = (MenBook) other;
        return (sellingPrice() >= mbobject.sellingPrice());
       }

Please note that OrderedByPrice is an interface

2 Answers 2

1

You are assigning to variable mobject (of type MenBook) the object other (of type Object), after checking that its type is of the correct one (getClass() != other.getClass()).

Sign up to request clarification or add additional context in comments.

Comments

0

You are creating a new MenBook object called mbObject and you assign the object called other to it.

The (MenBook) in front of other means you are casting the object called other to a MenBook object.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.