Skip to content

Instantly share code, notes, and snippets.

@kunosu
Created January 3, 2020 10:35
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 kunosu/40c66f5b2fe963cb973e32907f93052c to your computer and use it in GitHub Desktop.
Save kunosu/40c66f5b2fe963cb973e32907f93052c to your computer and use it in GitHub Desktop.
Javaメソッドの公範囲の設定方法
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.");
}
}
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