public interface B extends A {}
public interface B implements A {}
public interface B instanceOf A {}
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);
}
}
第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());
}}
第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.产生一个编译时错误
第5题:
下列程序段的输出结果是 String MyStr = "Hello,"; MyStr = MyStr + "World!"; System.out.println(MyStr);
A.Hello,World!
B.Hello,
C.World!
D.该程序段有语法错误
第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.)()
第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.该程序段有语法错误
第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题:
A.编译错误;
B.运行输出 "Hello cruel world";
C.编译无错,但运行时指示没有定义构造方法。
D.编译无错,但运行时指示没有正确定义main方法。