23 lines
733 B
Java
23 lines
733 B
Java
|
|
public class Day3Check2 {
|
|
public static void main(String[] args) {
|
|
|
|
//Rect-クラスをもとにrect-のインスタンスつくる
|
|
//3,4をRectangleのコンストラクタに渡す
|
|
Rectangle rectangle = new Rectangle(3, 4);
|
|
|
|
//Rect-はShapeを継承しているため親クラスのshowInfoメソッドを使える
|
|
rectangle.showInfo();
|
|
|
|
|
|
//JaGrクラスをもとにインスタンスをつくる
|
|
//変数の型はGreetingインタフェース型にしている
|
|
Greeting greeting = new JapaneseGreeting();
|
|
|
|
//greeetingのhelloメソッドよびだす
|
|
//実際に入っているインスタンスはJaGrなのでJaGrで作ったhello()が実行される
|
|
System.out.println(greeting.hello());
|
|
}
|
|
|
|
}
|