Java

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();
  //Overload
  String getCity(int id);
}

TokyoService



package test;

public class TokyoService implements IPrefecture {
  static final String[] cities = {"Chuo-ku", "Naniwa Ward"};
	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 = {"Shibuya Ward", "Shinjuku ward"};
  public OsakaService() {
    System.out.println("Osaka");
  }

  @Override
  public String[] getCities() {
    return cities;
  }

  @Override
  public String getCity(int id) {
    return cities[id];
  }
}

Recommended Posts

Java
Java
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
Java array
Studying Java ―― 9
Java scratch scratch
java (constructor)
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
java beginner 4
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework
[Java] Inheritance
FastScanner Java
java beginner 3
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)
JAVA (Map)
[java] interface
Java9 collection
Java basics
Java methods
Java inheritance
[Java] enum
[Java] FizzBuzzCounter
Studying Java ―― 8
Java array
Java (add)
Java method
Java (remove)
java serializable
JAVA memorandum