public interface B extends A {}
public interface B implements A {}
public interface B instanceOf A {}
public interface B inheritsFrom A {}
第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.该程序段有语法错误
第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.产生一个编译时错误
第4题:
下列选项中,()是正确的表达式。
第5题:
public class Foo { public void main (String args) { system.out.printIn(“Hello World.”); } } What is the result? ()
第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?()
第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?()
第8题:
下列哪项是String的字面量?()
第9题:
The program runs and prints “Hello”
An error causes compilation to fail.
The program runs and prints “Hello world!”
The program runs but aborts with an exception.
第10题:
“Hello”
‘world’
/u2345
new String(“good”)
第11题:
The program runs and prints “Hello”
An error causes compilation to fail.
The program runs and prints “Hello world!”
The program runs but aborts with an exception.
第12题:
<% String s = “hello world ” ;%>
<% = “hello world ” ;%>
<% = “hello world ” %>
<% ! “hello world ” %>
第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题:
A.编译错误;
B.运行输出 "Hello cruel world";
C.编译无错,但运行时指示没有定义构造方法。
D.编译无错,但运行时指示没有正确定义main方法。
第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?()
第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?()
第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?()
第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?()
第20题:
Compilation fails.
hello from a
hello from b
hello from b hello from a
hello from a hello from b
第21题:
5
6
7
12
13
第22题:
An exception is thrown.
The code does no compile.
“Hello World.” Is printed to the terminal.
The program exits without printing anything.
第23题:
SELECT SUBSTR( ‘Hello World’,1) FROM dual;
SELECT INITCAP(TRIM (‘Hello World’, 1,1)) FROM dual;
SELECT LOWER(SUBSTR(‘Hello World’, 1, 1) FROM dual;
SELECT LOWER(SUBSTR(‘Hello World’, 2, 1) FROM dual;
SELECT LOWER(TRIM (‘H’ FROM ‘Hello World’)) FROM dual;