I can not understand why the method say (String something) does not return "You do not know what the fish do not talk?"

There is a subclass of Fish

public class Fish extends Pet { int currentDepth=0; public int dive(int howDeep){ currentDepth=currentDepth + howDeep; System.out.println("Ныряю на глубину " + howDeep + " футов"); System.out.println("Я на глубине " + currentDepth + " футов ниже уровня моря"); return currentDepth; } public String say(String something){ return "Ты чё не знаешь, что рыбы не разговаривают?"; } } 

There is a main class FishMaster

 public class FishMaster { public static void main(String[] args) { Fish myFish = new Fish(); myFish.dive(2); myFish.dive(3); myFish.sleep(); myFish.say("Привет"); } } 

There is a super pet class

 public class Pet { int age; float weight; float height; String color; public void sleep(){ System.out.println("Спокойной ночи! До завтра"); } public void eat(){ System.out.println("Я очень голоден, давайте перекусим чипсами!"); } public String say(String aWord){ String petResponse = "Ну ладно!! " +aWord; return petResponse; } } 

There is a main class PetMaster

 public class PetMaster { public static void main(String[] args) { String petReaction; Pet myPet = new Pet(); myPet.eat(); petReaction = myPet.say("Чик!! Чирик!!"); System.out.println(petReaction); myPet.sleep(); } } 

This is all code. It is taken from the book. In the book, the line "Do you not know what the fish do not speak?" Is displayed, but for some reason it does not appear in my book.

The program outputs: Dive to a depth of 2 feet I am at a depth of 2 feet below sea level Dive to a depth of 3 feet I am at a depth of 5 feet below sea level Good night! Till tomorrow

Closed due to the fact that off-topic participants are Roman C , fori1ton , LFC , andreymal , freim on Feb. 13 at 8:27 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reasons:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - fori1ton, andreymal, freim
  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Roman C, LFC
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Why did you decide that he does not return anything? - Kirill Malyshev
  • What does sleep do? How is Pet defined? - Alexey Ten
  • Can you tell me what to fix, so that the line "You do not know what the fish do not speak?" (ಥ﹏ಥ) - Makaroni
  • Fish myPet = new Fish(); instead of Pet - VolArt

2 answers 2

The string is returned. But you do nothing with it.

 Fish myFish = new Fish(); ... System.out.println(myFish.say("Привет")); 
  • Oh, thank you very much;) - Makaroni
  • @Makaroni Please. Successes! The tick mark is to the left of the answer. - Igor
  • I thank) and I was just looking for how to close the question =) - Makaroni

You have two public static void main in the program, respectively, 2 entry points to it, at the moment the program starts from the FishMaster class and accordingly displays what is written there, you need to reassign the entry point to PetMaster, in intelij this is done via edit configuration -> main class