init
This commit is contained in:
41
Question15-Polymorphism/src/common/Car.java
Normal file
41
Question15-Polymorphism/src/common/Car.java
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Car {
|
||||
|
||||
private String name;
|
||||
private int speed;
|
||||
|
||||
public Car(String name, int speed) {
|
||||
this.name = name;
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 設定されたスピードで走る
|
||||
*/
|
||||
public void run() {
|
||||
System.out.println(this.name + "は時速" + this.speed + "で走った");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(int speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
}
|
||||
19
Question15-Polymorphism/src/common/SportsCar.java
Normal file
19
Question15-Polymorphism/src/common/SportsCar.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* PTra12_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class SportsCar extends Car{
|
||||
public SportsCar() {
|
||||
super("スポーツカー", 100);
|
||||
}
|
||||
/**
|
||||
* 設定されたスピードの3倍の速度で走る
|
||||
*/
|
||||
public void turbo() {
|
||||
System.out.println(super.getName() + "は時速" + (super.getSpeed() * 3 ) + "で走った");
|
||||
}
|
||||
}
|
||||
13
Question15-Polymorphism/src/common/Truck.java
Normal file
13
Question15-Polymorphism/src/common/Truck.java
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* PTra12_01.java
|
||||
* 作成 Rhizome
|
||||
*------------------------------------------------------------
|
||||
* Copyright(c) Rhizome Inc. All Rights Reserved.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public class Truck extends Car{
|
||||
public Truck() {
|
||||
super("トラック", 30);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user