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

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

 collie

B

 harrier

C

 Compilation fails.

D

 collie harrier

E

 An exception is thrown at runtime.


相似考题
更多“单选题public class Test {  public enum Dogs {collie, harrier};  public static void main(String [] args) {  Dogs myDog = Dogs.collie;  switch (myDog) {  case collie:  System.out.print(”collie “); case harrier:  System.out.print(”harrier “);  }  }  }  What is ”相关问题
  • 第1题:

    给出下列代码段: public class ex38 { public static void main (String args [ ] ) { int m; switch(m) { case 0: System.out.println ( "case 0" ); case 1:System.out.println("case 1");break; case 2: default: System.out.print in ("default") } } 下列m的______值将引起"default"的输出。

    A.0

    B.1

    C.2

    D.以上答案都不正确


    正确答案:C

  • 第2题:

    阅读下列代码 public class Test { public static void main(String args[]) { String s = "Test"; switch (s) { case "Java": System.out.print("Java"); break; case "Language": System.out.print("Language"); break; case "Test": System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译出错


    正确答案:D
    解析:switch语句根据其后表达式的值从多个分支中选择一个来执行,表达式只能返回int、byte、short和char类型。

  • 第3题:

    阅读卜列代码 public class Test2005{ public static voidmain(Stringargs[]){ String s="Test"; switch(s){ case"Java":System.out.print("Java"); break; case"Language":System.out.print("Language"); break; case"Test":System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译时出错


    正确答案:D
    解析: 本题考查switch语句的用法。switch语句是多分支语句,即根据表达式的值来执行多个操作中的一个。在 switch语句中,“表达式”的返回值类型必须是这几种类型之一:int,byte,char,short。本题中,switch的表达式s是一个字符串String类型的值,它不是int、byte、char、short中的任意一个。因此表达式s的类型不对,编译时出错。

  • 第4题:

    阅读下面代码段:public class Test{ public static void main(String args[]){ char ch; switch(ch) { case'a':System.out.print("abc");break; case'b':System.out.print("ab"); case'c':System.out.print("c");break; default:System.out.print("abc"); } }}不输出"abc"的ch值是 ( )

    A.'a'

    B.'b'

    C.'c'

    D.'d'


    正确答案:C
    解析:该题测试的是考生对switch语句的掌握,执行时,switch语句根据表达式返回的值与每个case子句的值相比较。如果匹配成功,则执行该case子句后的语句序列,直到执行到break语句或switch语句结束,然后跳出switch语句。如果匹配不成功,则跳转到default语句。本题中,如果ch的值是'a',则输出结果是"abc"。如果ch的值是'b',则输出的是"ab",而这时输出还没结束,所以继续输出字符串"c",所以它的最终结果也是输出"abc"。如果ch的值是'd',则它就跳转到default输出"abc"。如果ch的值是'c',则输出结果是"c",所以选项C是正确的。

  • 第5题:

    class Dog { }  class Harrier extends Dog { }  class DogTest {  public static void main(String [] args) {  Dog d1 = new Dog();  Harrier h1 = new Harrier();  Dog d2 = h1;  Harrier h2 = (Harrier) d2;  Harrier h3 = d2;  }  }  下面哪一项是正确的?() 

    • A、编译失败
    • B、2个Dog对象被创建
    • C、2个Harrier对象被创建
    • D、3个Harrier对象被创建

    正确答案:A

  • 第6题:

    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.

    正确答案:D

  • 第7题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()  

    • A、 AC
    • B、 BD
    • C、 ACD
    • D、 ABCD
    • E、 Compilation fails.

    正确答案:C

  • 第8题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (RuntimeException ex) {  System.out.print(“B”);  }  catch (Exception ex1) {  System.out.print(“C”);  }   finally {  System.out.print(“D”);  }  System.out.print(“E”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result?()  

    • A、 BD
    • B、 BCD
    • C、 BDE
    • D、 BCDE
    • E、 ABCDE
    • F、 Compilation fails.

    正确答案:C

  • 第9题:

    单选题
    现有:  class Dog{ }  class Harrier extends Dog  { }       class DogTest{   public  static void main (String  []  args) {      Dog dl=new Dog();      Harrier hl=new Harrier();      Dog d2=hl;   Harrier h2=  (Harrier) d2;      Harrier h3=d2;     }      }  下面哪一项是正确的?()
    A

    2个Dog对象被创建

    B

    2个Harrier对象被创建

    C

    3个Harrier对象被创建

    D

    编译失败


    正确答案: C
    解析: 暂无解析

  • 第10题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? ()
    A

     AB

    B

     BC

    C

     ABC

    D

     BCD

    E

     Compilation fails.


    正确答案: D
    解析: 暂无解析

  • 第11题:

    单选题
    class Dog { }  class Harrier extends Dog { }  class DogTest {  public static void main(String [] args) {  Dog d1 = new Dog();  Harrier h1 = new Harrier();  Dog d2 = h1;  Harrier h2 = (Harrier) d2;  Harrier h3 = d2;  }  }  下面哪一项是正确的?()
    A

    编译失败

    B

    2个Dog对象被创建

    C

    2个Harrier对象被创建

    D

    3个Harrier对象被创建


    正确答案: C
    解析: 暂无解析

  • 第12题:

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

     collie

    B

     harrier

    C

     Compilation fails.

    D

     collie harrier

    E

     An exception is thrown at runtime.


    正确答案: A
    解析: 暂无解析

  • 第13题:

    下列程序执行的结果是______。 public class ex6 { public static void main(String[] args) { char ch='8'; int r=10; switch(ch+l) { case '7': r=r+3; case '8': r=r+5; case '9': r=r+6; break; default: ; } System.out.print(r); } }

    A.14

    B.13

    C.16

    D.10


    正确答案:C

  • 第14题:

    下列程序执行之后,将输出 public class exl9 { public static void main(string[] args) { int x=3; int y=7; switch(y/x){ case 1: y*=2; break; case 2: y*=3; break; case 3: y*=4; break; default: y=0; } System.out.print(y); } }

    A.28

    B.21

    C.14

    D.0


    正确答案:B

  • 第15题:

    阅读下列代码 public class Test2005{ public static void main(String args[]){ String s="Test"; switch(s){ case"Java":System.out.print("Java"); break; case"Language":System.out.print("Lan- guage"); break; case"Test":System.out.print("Test"); break; } } } 其运行结果是( )。

    A.Java

    B.Language

    C.Test

    D.编译时出错


    正确答案:D
    D。【解析】本题考查switch语句的用法。switch语句是多分支语句,即根据表达式的值来执行多个操作中的一个。在switch语句中,”表达式”的返回值类型必须是这几种类型之一:int、byte、char、short。本题中,switch的表达式s是一个字符串Strin9类型的值,它不是int、byte、char、short中的任意一个。因此表达式s的类型不对,编译时出错。

  • 第16题:

    public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?() 

    • A、 foofoofoofoofoo
    • B、 foobarfoobarbar
    • C、 foobarfoofoofoo
    • D、 foobarfoobarfoo
    • E、 barbarbarbarbar
    • F、 foofoofoobarbar
    • G、 foofoofoobarfoo

    正确答案:D

  • 第17题:

    Public class test (  Public static void main (String args[])  (  System.out.printIn (6 ^ 3);  )  )   What is the output?()


    正确答案:5

  • 第18题:

    现有:  class Dog{ }  class Harrier extends Dog  { }       class DogTest{   public  static void main (String  []  args) {      Dog dl=new Dog();      Harrier hl=new Harrier();      Dog d2=hl;   Harrier h2=  (Harrier) d2;      Harrier h3=d2;     }      }  下面哪一项是正确的?()    

    • A、2个Dog对象被创建
    • B、2个Harrier对象被创建
    • C、3个Harrier对象被创建
    • D、编译失败

    正确答案:D

  • 第19题:

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

    • A、 collie
    • B、 harrier
    • C、 Compilation fails.
    • D、 collie harrier
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第20题:

    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new RuntimeException();  }  }  What is the result? () 

    • A、 AB
    • B、 BC
    • C、 ABC
    • D、 BCD
    • E、 Compilation fails.

    正确答案:D

  • 第21题:

    单选题
    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.


    正确答案: A
    解析: 暂无解析

  • 第22题:

    单选题
    下列程序的运行结果是(  )。class Shape{ public Shape(){ System.out.print("Shape"); }}class Circle extends Shape{ public Circle(){ System.out.print("Circle"); }}public class Test{ public static void main(String[]args){ Shape d=new Circle(); }}
    A

    Shape

    B

    Circle

    C

    ShapeCircle

    D

    程序有错误


    正确答案: B
    解析:
    继承是面向对象编程的一个主要优点之一,它对如何设计Java类有着直接的影响。该程序首先编写了一个Shape的类,然后又编写一个类Circle去继承Shape类。由于子类拥有父类所有的属性和方法,所以输出的是ShapeCircle。

  • 第23题:

    单选题
    public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”); }  catch (Exception ex) {  System.out.print(“B”);  }  finally {  System.out.print(“C”);  }  System.out.print(“D”);  }   public static void badMethod() {} }  What is the result?()
    A

     AC

    B

     BD

    C

     ACD

    D

     ABCD

    E

     Compilation fails.


    正确答案: D
    解析: 暂无解析

  • 第24题:

    单选题
    public class Base {  public static final String FOO = “foo”;  public static void main(String[] args) {  Base b = new Base();  Sub s = new Sub();  System.out.print(Base.FOO);  System.out.print(Sub.FOO);  System.out.print(b.FOO);  System.out.print(s.FOO);  System.out.print(((Base)s).FOO);  } }  class Sub extends Base {public static final String FOO=bar;}  What is the result?()
    A

     foofoofoofoofoo

    B

     foobarfoobarbar

    C

     foobarfoofoofoo

    D

     foobarfoobarfoo

    E

     barbarbarbarbar

    F

     foofoofoobarbar

    G

     foofoofoobarfoo


    正确答案: B
    解析: 暂无解析