Javaの問題:パブリックタイプ****は独自のファイルで定義する必要があります



Problems With Java Public Type Must Be Defined Its Own File



Eclipseには問題があります。パブリックタイプ****は独自のファイルで定義する必要があります

解決策:1。ファイル名をパブリッククラスと同じ名前に変更します
2.クラス名を同じファイル名に変更します
3.サブクラス 継承 親クラスの場合、パブリック変更を使用する必要はありません(3番目がより一般的です)

次の図は、3番目の問題の例と解決策を示しています。
画像
パブリックを削除するだけ



```java /** * */ package dometest /** * @author QJ * */ public class Dotes5 { /** * @author QJ * */ public Dotes5(){//Constructor System.out.println('A's Constructor') } {//Construct the code block System.out.println('A's construction code block') } static {//Static code block System.out.println('A static code block') } } class Dotes6 extends Dotes5{ //When the subclass inherits the parent class, there is no need to use public modification public Dotes6() { System.out.println('B's Constructor') } {//Construct the code block System.out.println('B's construction code block') } static {//Static code block System.out.println('B's static code block') } public static void main(String[] args) { Dotes6 b = new Dotes6() } }
|_+_|