public enum searchengines{Google, Yahoo, Bing, Exhead, Baidu};末尾のカンマはオプションで、両方の書き込みは合法です。
enginesSearch engine = 検索エンジン.Google;すべての列挙型は、class java.lang.Enum クラスは 1 つの親からしか継承できず、複数のインタフェースから継承できるためです。
for( 検索エンジン エンジン: searchengines.values()) {
System.out.println(エンジン);
}
public class EnumExample {Output:
public enum searchengines{
Google(160), Yahoo(66.4f), Bing(7.f), Baidu(66), Ask(4.6f);
プライベートフロートビジター。
private searchengines(float visitors) {
this.visitors = visitors;
}
}
public static void main(String[] args) {
for( search engines: searchengines.values()) {
System.out.println("検索エンジン: "+engine+"
visitors: "+engine.visitors+" millions");
}
}
}
検索エンジン: Googleの訪問者: 1億6000万人定数が宣言されています static および finalであり、一度作成すると変更できません。
検索エンジン: Yahooの訪問者: 664000><00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 Baiduの訪問者:6600万
検索エンジン:訪問者に質問:460万
google search engines = searchengines.Google;
if(google.equals(GoogleSearchengines)))
System.out.println("等しいとの比較");
if(google == searchengines.Google)
System.out.println("==との比較");
public class EnumExample{
public enum searchengines{
Google(160), Yahoo(66.4f), Bing(7.f), Baidu(66), Ask(4.6f);
プライベートフロートビジター。
private searchengines(float visitors) {
this.visitors = visitors;
}
}
検索エンジン名。
EnumExample(検索エンジン名){
this.name=name;
}
public void slogan() {
switch (name) {
Google:
System.out.println("悪意を持たない、悪を行わない");
estate;
box Yahoo:
System.out.println("Yahoo! It's You.ヤフーですか?
estate;
box Bing:
System.out.println("Bingは行うためのものです。");
estate;
box Baidu:
System.out.println("Baiduは中国語をよく知っている");
estate;
box Ask:
System.out.println("質問は何ですか?");
estate;
}
}
public static void main(String[] args) {
Google Example = new ExampleNumber(SearchEngines.Google);
google.slogan();
例 enum yahoo = new 例 Enum(Searchengines.Yahoo);
yahoo.slogan();
例 Num bing = new SampleNum(SearchEngines.Bing);
bing.slogan();
Baidu Example Enum = new Baidu Example Enum(SearchEngines.Baidu);
baidu.slogan();
EnumExample ask = new EnumExample(Searchengines.Ask);
ask.slogan();
}
}
toString は定数の名前を返します:関数 valueOf() は、メソッド toString()、名前を付けると定数が返されます:
System.out.println(yahoo.toString());
System.out.println(yahoo.valueOf("Yahoo"));
System.out.println(google.compareTo(yahoo));
Please disable your ad blocker and refresh the window to use this website.