Answer the question
In order to leave comments, you need to log in
Why doesn't return work in java?
Return does not work in the say() (class Pet) method when I call from the super class, the same situation when I call the say() (class Fish) method from the main, here I tried to override the say () method from the Pet class.
one)
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;
}
}
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 "Рыбы не разговаривают";
}
}
public class PetMaster {
public static void main(String[] args) {
Pet myPet = new Pet();
Fish myFish = new Fish();
myPet.say("давай");
myFish.say("давай");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question