Created
January 3, 2020 10:35
-
-
Save kunosu/40c66f5b2fe963cb973e32907f93052c to your computer and use it in GitHub Desktop.
Javaメソッドの公範囲の設定方法
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 Aclass { | |
public void method1() { | |
System.out.println("Called public Aclass.method1."); | |
} | |
protected void method2() { | |
System.out.println("Called protected Aclass.method2."); | |
} | |
private void method3() { | |
System.out.println("Called private Aclass.method3."); | |
} | |
} |
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
import java.util.*; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
Aclass instance = new Aclass(); | |
instance.method1(); // → OK | |
instance.method2(); // → OK | |
//instance.method3(); // → ビルドエラー | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment