单选题public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?()Apublic interface B extends A {}Bpublic int

题目
单选题
public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?()
A

 public interface B extends A {}

B

 public interface B implements A {}

C

 public interface B instanceOf A {}

D

 public interface B inheritsFrom A {}


相似考题

3.A Windows Communication Foundation (WCF) solution uses the following contracts. (Line numbers are included for reference only.)01 [ServiceContract(CallbackContract=typeof(INameService))]02 public interface IGreetingService03 {04 [OperationContract]05 string GetMessage();06 }07 [ServiceContract]08 public interface INameService09 {10 [OperationContract]11 string GetName();12 }The code that implements the IGreetingService interface is as follows:20 public class GreetingService : IGreetingService21{22 public string GetMessage()23 {24 INameService clientChannel = OperationContext.Current.GetCallbackChannel();25 string clientName = clientChannel.GetName();26 return String.Format("Hello {0}", clientName);27 }28 }The service is self-hosted. The hosting code is as follows:30 ServiceHost host = new ServiceHost(typeof(GreetingService));31 NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);32 host.AddServiceEndpoint("MyApplication.IGreetingService", binding, "net.tcp//localhost:12345");33 host.Open();The code that implements the lNameService interface is as follows:40 class NameService : INameService41 {42 string name;43 public NameService(string name)44 {45 this.name = name;46 }47 public string GetName()48 {49 return name;50 }51 }Currently, this code fails at runtime, and an InvalidOperationException is thrown at line 25. You need to correct the code so that the call from the service back to the client completes successfully. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)()

更多“public interface A {  String DEFAULT_GREETING = “Hello World”相关问题
  • 第1题:

    interface Playable {

    void play();

    }

    interface Bounceable {

    void play();

    }

    interface Rollable extends Playable, Bounceable {

    Ball ball = new Ball("PingPang");

    }

    class Ball implements Rollable {

    private String name;

    public String getName() {

    return name;

    }

    public Ball(String name) {

    this.name = name;

    }

    public void play() {

    ball = new Ball("Football");

    System.out.println(ball.getName());

    }

    }

    这个错误不容易发现。


    正确答案:

     

    错。"interface Rollable extends Playable, Bounceable"没有问题。interface 可继承多个

    interfaces,所以这里没错。问题出在interface Rollable 里的"Ball ball = new Ball("PingPang");"。

    任何在interface 里声明的interface variable (接口变量,也可称成员变量),默认为public static

    final。也就是说"Ball ball = new Ball("PingPang");"实际上是"public static final Ball ball = new

    Ball("PingPang");"。在Ball 类的Play()方法中,"ball = new Ball("Football");"改变了ball 的

    reference,而这里的ball 来自Rollable interface,Rollable interface 里的ball 是public static final

    的,final 的object 是不能被改变reference 的。因此编译器将在"ball = new Ball("Football");"

    这里显示有错。

  • 第2题:

    下列程序段的输出结果是 String MyStr = "Hello,"; MyStr = MyStr + "World!"; System.out.println(MyStr);

    A.Hello,World!

    B.Hello,

    C.World!

    D.该程序段有语法错误


    正确答案:A
    解析:String类型可以直接使用“+”进行连接运算。

  • 第3题:

    下面的代码实现一个简单的Applet: import java.applet.Applet; import java.awt.*; public class Sample extends Applet { private String text="Hello World"; public void init() { add(new Label(text)); } public Sample(String string) { text=string; } } 通过下面的HTML文件访问: <html> <title>Sample Applet</title> <body> <applet code="Sample.class"width=200 height=200></applet> </body> </html> 当编译和运行该小程序时会出现什么结果,请选择正确的答案。( )

    A.将会出现“Hello World"

    B.将会产生一个运行时错误

    C.什么都没有

    D.产生一个编译时错误


    正确答案:D
    解析:该题考查对Applet具体编程的理解。实际上就是考查APplet编程与 Application编程的区别。在应用程序编程中,通常由主类的构造函数和main()方法,在主类的构造函数里面进行一些一次性的初始化工作。而在小程序的编程中,也有主类,既然有类也就有相应的构造函数。但是要知道,Applet是在浏览器或者是通过专门的工具运行的,在创建Applet时,不能通过任何手段给Applet传递参数,所以构造函数应该是不能有参数的。但是,这种错误在编译时并不报错,因为它并没有任何的语法错误,只是会在运行时出错,系统会告诉你无法实例化小程序。注意,本题如果将构造函数改成下面的形式,则编译与运行时都不会出错。public Sample (String string){text="aaaaa";}它的效果与将语句text="aaaaa"放在init()函数里的效果是—样的。也就是说,创建Applet时的初始化工作能放在构造函数里实现的,完全可以放到init()函数里实现。但是,反之,能在init()函数里实现的代码却不一定能在构造函数里实现。这也就是为什么在小程序编程中不用构造函数的原因。故本题答案是D。

  • 第4题:

    下列选项中,()是正确的表达式。 

    • A、<% String s = “hello world ” ;%>  
    • B、<% = “hello world ” ;%> 
    • C、<% = “hello world ” %>  
    • D、<% ! “hello world ” %>

    正确答案:C

  • 第5题:

    public class Foo {   public void main (String args) {   system.out.printIn(“Hello World.”);   }   }   What is the result? () 

    • A、 An exception is thrown.
    • B、 The code does no compile.
    • C、 “Hello World.” Is printed to the terminal.
    • D、 The program exits without printing anything.

    正确答案:A

  • 第6题:

    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()  

    • A、 Compilation fails.
    • B、 hello from a
    • C、 hello from b
    • D、 hello from b hello from a
    • E、 hello from a hello from b

    正确答案:A

  • 第7题:

    public class X {   public static void main (Stringargs) {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s) {   s += “world!”;   }   }   What is the result?() 

    • A、The program runs and prints “Hello”
    • B、An error causes compilation to fail.
    • C、The program runs and prints “Hello world!”
    • D、The program runs but aborts with an exception.

    正确答案:A

  • 第8题:

    下列哪项是String的字面量?() 

    • A、“Hello”
    • B、‘world’
    • C、/u2345
    • D、new String(“good”)

    正确答案:A

  • 第9题:

    单选题
    public class X {   public static void main (Stringargs) {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s) {   s += “world!”;   }   }   What is the result?()
    A

    The program runs and prints “Hello”

    B

    An error causes compilation to fail.

    C

    The program runs and prints “Hello world!”

    D

    The program runs but aborts with an exception.


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

  • 第10题:

    单选题
    下列哪项是String的字面量?()
    A

    “Hello”

    B

    ‘world’

    C

    /u2345

    D

    new String(“good”)


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

  • 第11题:

    单选题
    public class X {   public static void main (String[]args)   {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s)  {   s += “world!”;      }   }      What is the result?()
    A

     The program runs and prints “Hello”

    B

     An error causes compilation to fail.

    C

     The program runs and prints “Hello world!”

    D

     The program runs but aborts with an exception.


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

  • 第12题:

    单选题
    下列选项中,()是正确的表达式。
    A

    <% String s = “hello world ” ;%>  

    B

    <% = “hello world ” ;%> 

    C

    <% = “hello world ” %>  

    D

    <% ! “hello world ” %>


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

  • 第13题:

    写出程序运行的结果

    Public class Base

    Public virtual string Hello() {return “Base”;}

    Public class Sub:Base

    Public override string Hello() {return “Sub”;}

    1. Base b = new Base(); b.Hello;

    2. Sub s = new Sub(); s.Hello;

    3. Base b = new Sub (); b.Hello;

    4. Sub s = new Base(); s.Hello;


    正确答案:
     

  • 第14题:

    下列程序段的输出是( )。 public class Test { public static void main (String args[ ]) { String ss1 = new String("hello"); String ss2 = new String("hello"); System.out.println(ssl == ss2); System.out.println (ssequals(ss2)); } }

    A.true, false

    B.true, true

    C.false, true

    D.false, false


  • 第15题:

    编译和运行以下代码的结果为:public class MyMain{public static void main(String argv){System.out.println("Hello cruel world");}}

    A.编译错误;

    B.运行输出 "Hello cruel world";

    C.编译无错,但运行时指示没有定义构造方法。

    D.编译无错,但运行时指示没有正确定义main方法。


    正确答案:D

  • 第16题:

    public interface A {  String DEFAULT_GREETING = “Hello World”;  public void method1();  }  A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?() 

    • A、 public interface B extends A {}
    • B、 public interface B implements A {}
    • C、 public interface B instanceOf A {}
    • D、 public interface B inheritsFrom A {}

    正确答案:A

  • 第17题:

    public class Foo {  public void main( String[] args ) {  System.out.println( “Hello” + args[0] );  }  }   What is the result if this code is executed with the command line?()

    • A、 Hello
    • B、 Hello Foo
    • C、 Hello world
    • D、 Compilation fails.
    • E、 The code does not run.

    正确答案:E

  • 第18题:

     public class X {   public static void main (String[]args)   {   string s = new string (“Hello”);   modify(s);   System.out.printIn(s);   }   public static void modify (String s)  {   s += “world!”;      }   }      What is the result?()    

    • A、 The program runs and prints “Hello”
    • B、 An error causes compilation to fail.
    • C、 The program runs and prints “Hello world!”
    • D、 The program runs but aborts with an exception.

    正确答案:A

  • 第19题:

    10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

    • A、 Hello
    • B、 Hello World
    • C、 Compilation fails.
    • D、 Hello World 5
    • E、 The code runs with no output.
    • F、 An exception is thrown at runtime.

    正确答案:C

  • 第20题:

    单选题
    class A {  public A() {  System.out.println(“hello from a”);  }  }  class B extends A {  public B () {  System.out.println(“hello from b”);  super();  }  }  public class Test {  public static void main(String args[]) {  A a = new B();  }  }   What is the result when main is executed?()
    A

     Compilation fails.

    B

     hello from a

    C

     hello from b

    D

     hello from b hello from a

    E

     hello from a hello from b


    正确答案: B
    解析: Call to super must be first statement in constructor. 

  • 第21题:

    单选题
    What will be written to the standard output when the following program is run?()   public class Q03e4 {   public static void main(String args[]) {   String space = " ";   String composite = space + "hello" + space + space;   composite.concat("world");   String trimmed = composite.trim();   System.out.println(trimmed.length());   }   }
    A

    5

    B

    6

    C

    7

    D

    12

    E

    13


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

  • 第22题:

    单选题
    public class Foo {  public void main (String [] args)   {  system.out.printIn(“Hello World.”); } }  What is the result?()
    A

     An exception is thrown.

    B

     The code does no compile.

    C

     “Hello World.” Is printed to the terminal.

    D

     The program exits without printing anything.


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

  • 第23题:

    单选题
    Which SELECT statement will the result ‘ello World’ from the string ‘Hello World’?()
    A

    SELECT SUBSTR( ‘Hello World’,1) FROM dual;

    B

    SELECT INITCAP(TRIM (‘Hello World’, 1,1)) FROM dual;

    C

    SELECT LOWER(SUBSTR(‘Hello World’, 1, 1) FROM dual;

    D

    SELECT LOWER(SUBSTR(‘Hello World’, 2, 1) FROM dual;

    E

    SELECT LOWER(TRIM (‘H’ FROM ‘Hello World’)) FROM dual;


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