public interface A {  String DEFAULT_GREETING = “Hello World

题目
单选题
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 {}

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

第1题:

下列Applet程序中,指定s为字符串类型,将s绘制在屏幕上,请将程序补充完整。

import java.applet.Applet;

import java.awt.Craphics;

public class testl8_1 extends Applet {

______String s;

public void init ()

{

s=new String("Hello World");

}

public Void______(Graphics g) {

g.______(s,10,25);

}

}


正确答案:publicpaintdrawString
public,paint,drawString

第2题:

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");"

这里显示有错。

第3题:

下列程序的运行结果是【 】。

public class Test {

public static void main (String args[]) {

String s1="hello!";

System.out.println (s1.toUpperCase());

}}


正确答案:HELLO!
HELLO! 解析:在String类的常用方法中,toUpperCaee()方法将当前字符串中的所有小写字母转化成大写,其他字符保持不变。

第4题:

下面的代码实现一个简单的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。

第5题:

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

A.Hello,World!

B.Hello,

C.World!

D.该程序段有语法错误


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

第6题:

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 IGreetingService

03 {

04 [OperationContract]

05 string GetMessage();

06 }

07 [ServiceContract]

08 public interface INameService

09 {

10 [OperationContract]

11 string GetName();

12 }

The code that implements the IGreetingService interface is as follows:

20 public class GreetingService : IGreetingService

21{

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 : INameService

41 {

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.)()


参考答案:C, D

第7题:

写出程序运行的结果

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;


正确答案:
 

第8题:

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

A.Hello, World!

B.Hello,

C.World!

D.该程序段有语法错误


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

第9题:

下列程序段的输出是( )。 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


第10题:

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

A.编译错误;

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

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

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


正确答案:D

更多相关问题