Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liliy

  • one year ago

Assume that FarmAnimal contains this method: public String mySound() { return “moo”; } Write a method in the Cow class that overrides this method (same name and return type and parameters). The method in the Cow class must call the mySound method in FarmAnimal twice so that the end result is that the Cow’s method returns moomoo. Do not do this: return “moomoo”;

  • This Question is Closed
  1. liliy
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    public class Cow{ String mySound(){ return farmAnimal.mySound(); } } ?????

  2. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Okay so you have a class FarmAnimal and need to get one of it's methods. public class cow extends FarmAnimal. By extending FarmAnimal you get all of it's goodies(Methods, Properties, variables, functions, etc), that are allotted for use. For example if it's a protected method you cannot access it externally. next we need to override the method String mySound() @Override public String mySound() { //return } The problem is.... They don't want us to do "return moomoo" we need to call it twice, which is interesting.... Imo from here we can do a few things. I think we will do it this way. @Override public String mySound() { String s; s = super.mySound(); s += super.mySound(); return s; } The only issue I see is that since we are "Overriding" mySound, will it affect the super call? I personally don't think so because we are just overriding the data from super.mySound in our cow class, which the FarmAnimal should be left alone.. I am not 100% sure though. This is a really good example!

  3. liliy
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i acutally think im gonna do : return super.mySound()+super.mySound();

  4. KonradZuse
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    yeah, see what happens.

  5. A.Avinash_Goutham
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    i think u got to specify that mysound is the baseclass of cow and then it says u got to return the name o.o

  6. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.