This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Emp{ | |
private String name; | |
Emp(String name) { // 引数ありコンストラクタ | |
this.name = name; | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Emp{ | |
Emp() { // デフォルトコンストラクタ | |
System.out.println("初期化する"); | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Emp emp = new Emp(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
private String name; | |
Parent(String name) {// 引数ありコンストラクタを書くとデフォルトコンストラクタは生成されない | |
this.name = name; | |
} | |
} | |
class Child extends Parent{ | |
private int age; | |
Child(int age) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
for(int i = 0;;i++) { // 無限ループになる。コンパイル、実行時エラーも発生しない。 | |
System.out.println(i); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
for(;;) { // 無限ループになる。コンパイル、実行時エラーも発生しない。 | |
System.out.println("a"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
int i = 0; | |
for(i = 0;i<5;i++) | |
; // 空ステートメントが5回ループされる | |
System.out.println(i); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
for(int i = 0;;) { // 無限ループになる。コンパイル、実行時エラーも発生しない。 | |
System.out.println(i); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
for(int i=0;i < 5;i++) { | |
if(i >= 3) break; | |
} | |
System.out.println(i); // ここよくよく見るとスコープ外! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Parent { | |
public void angry() { | |
System.out.println("こら"); | |
} | |
} | |
class Child extends Parent{ | |
public void sorry() { | |
System.out.println("ごめん"); | |
} |
OlderNewer