Test.java
class Test {
public static void main(String[] args) {
System.out.println("Test");
}
}
bash
>javac Test.java
>java Test
Test
Index.java
package test;
public class Index {
public static void main(String[] args) {
TokyoService tokyo = new TokyoService();
for (String city : tokyo.getCities()) {
System.out.println(city);
}
OsakaService osaka = new OsakaService();
System.out.println(osaka.getCity(0));
}
}
IPrefecture
package test;
public interface IPrefecture {
String[] getCities();
//Surcharge
String getCity(int id);
}
TokyoService
package test;
public class TokyoService implements IPrefecture {
static final String[] cities = {"Chuo-ku", "Quartier Naniwa"};
public TokyoService() {
System.out.println("Osaka");
}
@Override
public String[] getCities() {
return cities;
}
@Override
public String getCity(int id) {
return cities[id];
}
}
OsakaService
package test;
public class OsakaService implements IPrefecture {
static final String[] cities = {"Quartier de Shibuya", "Quartier Shinjuku"};
public OsakaService() {
System.out.println("Osaka");
}
@Override
public String[] getCities() {
return cities;
}
@Override
public String getCity(int id) {
return cities[id];
}
}
Recommended Posts