[これがJava]第8章インタフェース確認問題3号
Soundableクラスでは、printSound()メソッドにはSoundableインタフェースタイプのパラメータがあります.main()メソッドでprintSound()を呼び出すと、CatとDogオブジェクトを送信して実行し、Rock CatとDogクラスを作成して「ニャー」と「ワン」をそれぞれ出力します.
package q03;
public interface Soundable {
String sound();
}
package q03;
public class SoundableExample {
private static void printSound(Soundable soundable) {
System.out.println(soundable.sound());
}
public static void main(String[] args) {
printSound(new Cat());
printSound(new Dog());
}
}



Reference
この問題について([これがJava]第8章インタフェース確認問題3号), 我々は、より多くの情報をここで見つけました https://velog.io/@xyunkyung/이것이-자바다-8장-인터페이스-확인문제-3번テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol