Skip to content

Instantly share code, notes, and snippets.

@takahashi-h5
Last active August 25, 2019 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takahashi-h5/7c3ea71d8b363791b897f5f0eb635099 to your computer and use it in GitHub Desktop.
Save takahashi-h5/7c3ea71d8b363791b897f5f0eb635099 to your computer and use it in GitHub Desktop.
class Emp{
private String name;
private int age;
Emp(String name) {
this(10); // thisはコンストラクタの先頭行に書く必要がある
this.name = name;
}
Emp(int age) {// this(10);でこのコンストラクタが呼ばれる
this.age = age;
}
}
public class Main {
public static void main(String[] args) {
Emp emp = new Emp("takahashi");
System.out.println(emp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment