Существует 5 классов: один основной с объектами, в классе ball существует логическая конструкция соответствии с которой результат всех действий будет выведен на консоль, остальные классы ссылаются на ball. Вопрос: как подключить метод tryRun и вызвать его в других классах? (схема сказки "Колобок").
Метод 1
public class Ball {
public void tryRun(boolean condition) {
if (condition){
System.out.println("the ball is eaten!");
} else{
System.out.println("the ball escaped!");
}
}
}
Метод 2
public class Hare {
public void tryEat(Ball ball) {
public void tryBall(true false){
}
}
}
Метод 3
public class Wolff {
public void tryEat(Ball ball) {
public void tryBall(true false){
}
}
}
Метод 4
public class Fox {
public void tryEat(Ball ball) {
public void tryBall() {
System.out.println(this.condition);
}
}
}
Основной метод
public class BallStory {
public static void main(String[] args) {
Ball ball = new Ball();
Hare hare = new Hare();
Wolff wolff = new Wolff();
Fox fox = new Fox();
hare.tryEat(ball);
wolff.tryEat(ball);
fox.tryEat(ball);
}
}