LoginSignup
0
0

More than 5 years have passed since last update.

public修飾子を指定したクラス定義の注意点

Last updated at Posted at 2016-06-17

Javaでは1ソースファイル中でpublic修飾子を付したクラスは1つしか定義することができない。

public class Hoge {
    public static void main(String[] args) {
        ...
    }
}

public class Piyo {
    ...
}

通常のクラス定義だけでなく、インターフェースや抽象クラスを同一ファイルで定義する場合も同じ。

public class Hoge implements Piyo {
    public static void main(String[] args) {
        ...
    }
}

public interface Piyo {
    ...
}
public class Hoge extends Piyo {
    public static void main(String[] args) {
        ...
    }
}

public abstract class Piyo {
    ...
}
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0