Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

liliy Group Title

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”;

  • one year ago
  • one year ago

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

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

    • one year ago
  2. KonradZuse Group Title
    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!

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

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

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

    yeah, see what happens.

    • one year ago
  5. A.Avinash_Goutham Group Title
    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

    • one year ago
    • Attachments:

See more questions >>>

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.