public class Test {  public enum Dogs {collie, harrier, shep

题目
单选题
public class Test {  public enum Dogs {collie, harrier, shepherd};  public static void main(String [] args) {  Dogs myDog = Dogs.shepherd;  switch (myDog) {  case collie:  System.out.print(”collie “);  case default:  System.out.print(”retriever “); case harrier:  System.out.print(”harrier “);  }  }  }  What is the result?()
A

 harrier

B

 shepherd

C

 retriever

D

 Compilation fails.

E

 retriever harrier

F

 An exception is thrown at runtime.

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

publicclassTest{publicenumDogs{collie,harrier};publicstaticvoidmain(String[]args){DogsmyDog=Dogs.collie;switch(myDog){casecollie:System.out.print(”collie);caseharrier:System.out.print(”harrier);}}}Whatistheresult?()

A.collie

B.harrier

C.Compilationfails.

D.collieharrier

E.Anexceptionisthrownatruntime.


参考答案:D

第2题:

下列哪个选项的java源文件代码片段是不正确的?

A.package testpackage; public class Test{ }

B.import java. io. *; package testpaekage; public class Test { }

C.import java.io.*; class Person { } public class Test { }

D.import java.io.*; import java. awt.*; public class Test{ }


正确答案:B
解析:Java中的package语句必须是源文件中除去说明以外的第一条语句,导入包语句可以有几个,但是必须位于package语句之后,其他类定义之前,一个源文件中可以有几个类,但最多只能有一个是public的,如果有,则源文件的文件名必须和该类的类名相同。

第3题:

下列关于Test类的定义中,正确的是______。

A) class Test implements Runnabte{

public void run(){}

public void someMethod(){}

B) class Test implements Rnuuable{

public void run();

}

C) class Test implements Rnuuable{

public void someMethod();

}

D) class Test implements Rnuuable{

public void someMethod();{}

}

A.

B.

C.

D.


正确答案:A

第4题:

在下列源代码文件Test.java中, ( )是正确的类定义。

A.public class test{

B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

C.public class Test extends T1,T2{

D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


正确答案:B

第5题:

下列哪个选项的java源文件程序段是不正确的? ( )

A.package testpackage; public class Test{ }

B.import java.io.*; package testpackage; public class Test{ }

C.import java.i.*; class Person{} public class Test{ }

D.import java.io.*; import java.awt.*; public class Test { }


正确答案:B

第6题:

publicclassTest{publicenumDogs{collie,harrier,shepherd};publicstaticvoidmain(String[]args){DogsmyDog=Dogs.shepherd;switch(myDog){casecollie:System.out.print(”collie);casedefault:System.out.print(”retriever);caseharrier:System.out.print(”harrier);}}}Whatistheresult?()

A.harrier

B.shepherd

C.retriever

D.Compilationfails.

E.retrieverharrier

F.Anexceptionisthrownatruntime.


参考答案:D

第7题:

在下列源代码文件Test.java中,正确定义类的代码是( )。

A.pblic class test { public int x=0; public test(int x) { this. x=x;} }

B.public class Test { public int x=0; public Test(int x) { this. x=x;} }

C.public class Test extends T1,T2{ public int x = 0; public Test(int x){ this. x = x; } }

D.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }


正确答案:B
解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

第8题:

在如下源代码文件Test.java中, 哪个是正确的类定义?()

A.public class test { public int x = 0; public test(int x) { this.x = x; } }

B.public class Test{ public int x=0; public Test(int x) { this.x = x; } }

C.public class Test extends T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }

D.public class


正确答案:BD

第9题:

下列关于Test类的定义中,正确的是( )。

A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }

B.class Test implements Runnable( puIblic void run; }

C.class Test implements Runnable( Dublic void someMethod[]; }

D.class Test implements Runnable( public void someMethod{} }


正确答案:A
A。【解析】java中实现多线程的方法之一就是实现Runnable接口中的run方法,把实现Runnable接口的子类对象传递给Thread类的构造函数。

第10题:

在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )

A.public class test { public int x=0; public test(int x) { this.x=x; } }

B.public class Test { public int x=0; public Test(int x) { this.x=x; } }

C.public class Test extends Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }

D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }


正确答案:B

更多相关问题