1. 程式人生 > >The public type Thread2 must be defined in its own file 到底是什麼意思??

The public type Thread2 must be defined in its own file 到底是什麼意思??

java中前面出現一個類 ,後面再定義類時總是不合法 比如:我已經定義了一個類Computer 在定義一個類Game 它就說公共型別Game 必須在它自己定義的資料夾中定義:

java的規範:一個java檔案中有且只能有一個宣告為public的class,例如同一個檔案中寫:
public class Computer{
.....
}
public class Game{
   ....
}
這樣是不行的,除非你寫兩個java檔案:一個Computer.java 一個Game.java
但是注意它的規範:“個java檔案中有且只能有一個宣告為public的class”,也就是說,只要有一個是宣告為public的就行了,另一個不為public是合法的,像這樣:
public class Computer{
.....
}
class Game{
   ....
}
這樣的話,你必須將此檔案取名為Computer.java(注意大小寫,檔名必須和宣告為public的class的類名完全一致。)
package test;
public abstract class TestAbstractDemo {
public abstract void hello();
}
class Foo extends TestAbstractDemo{
public void hello() {
System.out.println("hello");
}
}
這樣是可以的。但是你把Foo類前面加了public就出現了你之前那個錯。就算是繼承,他也是來源於他的父類的。只能寫一個public,而且這裡你的Foo類不止不能寫public,protected..也不行。因為抽象類只能是public ,abstract 或者final , - - 我覺得你這個問題應該就是這裡不對,給你個建議,下次再出現問題了就自己動手稍微改改就知道錯哪了,錯的多了你也就熟能生巧了,因為我一開始也是這樣。
這時,另一個類Game就是一個內部類了(也就是說Game這個類只能在Computer.java這個檔案裡面使用,外面的其它的類是不能進行訪問的。)

相關推薦

The public type Thread2 must be defined in its own file 到底是什麼意思??

java中前面出現一個類 ,後面再定義類時總是不合法 比如:我已經定義了一個類Computer 在定義一個類Game 它就說公共型別Game 必須在它自己定義的資料夾中定義: java的規範:一個java檔案中有且只能有一個宣告為public的class,例如同一個檔案中寫

【理解】column must appear in the GROUP BY clause or be used in an aggregate function

pin group func 函數 ear -- database nbsp like column "ms.xxx_time" must appear in the GROUP BY clause or be used in an aggregate function -

ORA-16433 The database must be opened in read write mode故障解決

eas archive ota chang corrupt must etl 腳本 指定 轉 一、首先刪除原有控制文件並新建控制文件 1、找到控制文件位置 SQL> show parameter control_files; NAME TYPE VALUE ---

A master URL must be set in your configuration問題解決方法

2.0 erro reflect sse native span pre park ons 1 Using Spark‘s default log4j profile: org/apache/spark/log4j-defaults.properties 2 16/1

mac上 go-delve 安裝出現The specified item could not be found in the keychain 解決方法

mon pen 方法 rar spec hub 錯誤 sys lib 安裝go語言的編譯環境,在安裝到 delve時候出現如下錯誤: If reporting this issue please do so at (not Homebrew/brew or Hom

spark 異常解決:A master URL must be set in your configuration

為了省去每次都建立spark物件,寫了一個基礎類SparkSessionBase,沒想到叢集丟擲異常:A master URL must be set in your configuration。原因就

宜立方商城中,mvn報錯'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-webmvc:jar

'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-webmvc:jar dependency.(groupId:artifactId:type:cl

Incorrect table definition; there can be only one auto column and it must be defined as a key解決

在建表的時候報這樣的錯:  提示的意思是我們建表的時候,如果自增一定要設定一個key,手殘沒有設主鍵 `id` BIGINT(20) NOT NULL AUTO_INCREMENT, 改一下:  `id` BIGINT(20) NOT NULL AUTO_INCR

Git初學使用記錄fatal: this operation must be run in a work tree解決辦法

fatal: this operation must be run in a work tree $ git add test.txt fatal: this operation must be run in a work tree 解決辦法 原因是我們把t

本地開發Spark,執行JavaSparkPi例子報錯:A master URL must be set in your configuration

錯誤資訊: Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties 18/08/21 18:39:27 INFO SparkContext: Running Spark versi

IDEA中如果報org.apache.spark.sparkException: A master URL must be set in your configuration

local 本地單執行緒local[K] 本地多執行緒(指定K個核心)local[*] 本地多執行緒(指定所有可用核心)spark://HOST:PORT 連線到指定的 Spark stand

解決A master URL must be set in your configuration

win7 + idea + spark 對應pmo檔案如下: <properties> <spark.version>2.0.2</spark.version> <scala.version>2.11&

The Scientific Problem That Must Be Experienced

This story is for Medium members.Continue with FacebookContinue with GoogleMedium curates expert stories from leading publishers exclusively for members (w

vscode 'type aliases' can only be used in a .ts file.

vscode 'type aliases' can only be used in a .ts file. 使用react-native cli生成react-native專案,app.js中報該錯誤 解決方法: 使用react-native

Eclipse啟動報錯:A Java Runtime Environment(JRE) or Java Development Kit(JDK) must be available in order.

找eclipse配置檔案eclipse.ini -startup plugins/org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar --launcher.library plugins/org.eclipse.equinox

【git】fatal: This operation must be run in a work tree

今天新建立一個工程,需要一個倉庫。 用git --bare init建立的empty的倉庫,不能git add, 會會報錯fatal: This operation must be run in a work tree 。 但是,據說用git init的可以。 解決

Assembly must be registered in isolation

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.

[git] fatal: This operation must be run in a work tree

換了臺新電腦,然後重新安裝了最新版本的Git Extension。 然後新建Git Repo 然後就遇到了這個問題 WTF, 以前沒見過 好吧,各種上網查資料,折騰半天沒解決 後來在Stack Overflow上面找到答案 對的,我的目錄錯了,WTF 對,

在keychain tool裡,Request a certificate時,出錯''The specified item could not be found in the keychain"

解決辦法是:restart keychain tool, and then 在keychain tool裡,不要選擇"keys" item,應該選擇"all items",and then try again! (make sure you see "Let me spec

[git] fatal: This operation must be run in a work tree

        在使用git  init --bare 進行建立裸倉庫之後,在使用git 其它的命令都會出現fatal:This operation must be run in a work tree 問題,處理方法:         先touch readme 因為在建