LoginSignup
1
1

More than 5 years have passed since last update.

インターフェース書いてみた。

Last updated at Posted at 2012-02-16

javaplayer:自分で名付けたパッケージ

インターフェース書いてみた。
うーん、規定集すか。
ポリモーフィズムの実現にどう絡むのか見ていきたい。
勉強時間、他のsampleも加えて
1h45m -> 10分くらいに抑えたいね。
※Javaのオブジェクト指向がゼッタイにわかる本から学習
少しprintする文字とか変更している。
simpleでいい感じがする。

インターフェース

AVPlayer.java

//AVPlayer

package javaplayer;

public interface AVPlayer {

    public void play();

}

インターフェースを実装したクラス

AudioPlayer.java

//AudioPlayer

package javaplayer;

public class AudioPlayer implements AVPlayer{

    public void play(){

        System.out.println("Music Start");        

    }

}

インターフェースを実装したクラス

VideoPlayer.java

//VideoPlayer

package javaplayer;

public class VideoPlayer implements AVPlayer{

    public void play(){

        System.out.println("Video Start");

    }


}

mainファイル

Owner.java

//Owner

package javaplayer;

public class Owner{

    public static void main(String[] args){

        AudioPlayer myAudioPlayer = new AudioPlayer();
        VideoPlayer myVideoPlayer = new VideoPlayer();

        AVPlayer myAVPlayer = myAudioPlayer;
        myAVPlayer.play();

    }    

}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1