Output is correct but honestly I completely don;t undestand why when I compile program without writing whatever it gives result:
Why the program doesnt see sleep method() but that sees eat() and play() methods??
Second thing is question: what is wrong with my solution? :)
It gives correct output:
Amigo: Mmmmm, beef
Amigo: knock knock
Amigo: Zzzzzzz...1 s
package com.codegym.task.task23.task2311;
/*
Repeating threads
*/
public class Solution {
public final String name;
public final String food;
public final String sound;
public Solution(String name, String food, String sound) {
this.name = name;
this.food = food;
this.sound = sound;
}
public void eat() {
System.out.println(name + ": Mmmmm, " + food);
}
public void play() {
System.out.println(name + ": " + sound + " " + sound);
}
public void sleep(long milliseconds) {
System.out.println(name + ": Zzzzzzz..." + (milliseconds / 1000) + " s");
}
public void live() throws InterruptedException {
Thread thread = new Thread() {
public void run() {
try {
someActions();
} catch (Exception e) {
e.printStackTrace();
}
}
private void someActions() throws InterruptedException {
eat();
play();
Solution solution = new Solution(name,food,sound);
solution.sleep(1000);
}
};
thread.start();
thread.join();
}
public static void main(String[] args) throws InterruptedException {
new Solution("Amigo", "beef", "knock").live();
}
}