单选题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};  pu”相关问题
  • 第1题:

    下列哪个选项的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的,如果有,则源文件的文件名必须和该类的类名相同。

  • 第2题:

    下面程序的运行结果为( )。 include using namespace std; class A{ pu

    下面程序的运行结果为( )。 #include <iostream> using namespace std; class A{ public: A(){cout<<" ";} ~A(){cout<<" ";} } class B:public A{ public: B(){cout<<" ";} ~B(){cout<<" ";} } void main(){ B b; }

    A.1234

    B.1324

    C.1342

    D.3142


    正确答案:C
    解析:构造函数和析构函数系统可以自动调用。先执行其基类构造函数,输出1;执行派生类的构造函数,输出3;执行派生类析构函数,输出4;执行基类析构函数,输出2。

  • 第3题:

    下列关于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类的构造函数。

  • 第4题:

    在下列源代码文件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

  • 第5题:

    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?() 

    • A、 x = 0
    • B、 x = 42
    • C、 Compilation fails because of an error in line 2 of class Test2.
    • D、 Compilation fails because of an error in line 3 of class Test1.
    • E、 Compilation fails because of an error in line 4 of class Test2.

    正确答案:C

  • 第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 Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

    • A、 0
    • B、 1
    • C、 2
    • D、 Compilation fails.

    正确答案:D

  • 第8题:

    public class Test {} What is the prototype of the default constructor?()  

    • A、 Test()
    • B、 Test(void)
    • C、 public Test()
    • D、 public Test(void)
    • E、 public void Test()

    正确答案:C

  • 第9题:

    单选题
    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对象被创建


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

  • 第10题:

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


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

  • 第11题:

    单选题
    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?()
    A

     x = 0

    B

     x = 42

    C

     Compilation fails because of an error in line 2 of class Test2.

    D

     Compilation fails because of an error in line 3 of class Test1.

    E

     Compilation fails because of an error in line 4 of class Test2.


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

  • 第12题:

    单选题
    下列程序的运行结果是(  )。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。

  • 第13题:

    在下列源代码文件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。

  • 第14题:

    下列哪个选项的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

  • 第15题:

    在下列源代码文件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

  • 第16题:

    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

  • 第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题:

    You work as an application developer at Certkiller .com. You have recently created a custom collection class named ShoppingList for a local supermarket. This custom class will include ShoppinItem objects that have the public properties listed below. * Name * AisleNumber * OnDiscount You are required to enable users of your class to iterate through the ShoppingList collection, and to list each product name and aisle number using the foreach statement.You need to achieve this by declaring the appropriate code.What code should you use?()

    • A、 public class ShoppingList : ICollection {// Class implementation }
    • B、 public class ShoppingList : IEnumerator, IEnumerable {// Class implementation }
    • C、 public class ShoppingList : Ilist {// Class implementation }
    • D、 public class ShoppingList : Enum {// Class implementation }

    正确答案:B

  • 第21题:

    单选题
    现有:  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
    解析: 暂无解析

  • 第22题:

    单选题
    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
    解析: 暂无解析

  • 第23题:

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

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

  • 第24题:

    单选题
    public class Test {} What is the prototype of the default constructor?()
    A

     Test()

    B

     Test(void)

    C

     public Test()

    D

     public Test(void)

    E

     public void Test()


    正确答案: D
    解析: The correct answer to this question is C. The default constructor always takes the same access of the class. In this case, the class is public and so does the default constructor.