编译器将显示第7行有错误
程序编译并打印true
程序编译并打印false
程序编译但在第7行引起了一个运行期意外
第1题:
阅读下列代码段,选出该代码段的正确文件名( )。 class A { void method1() { System.out.println("method1 in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }
A.A.java
B.A.class
C.B.class
D.B.java
第2题:
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 T1, T2 { public int x = 0; public Test (int x) { this.x = x; } }
D.public class
第3题:
试题八(共15分)
阅读以下说明和Java程序代码,将应填入(n) 处的字句写在答题纸的对应栏内。
[说明]
在下面的 Java 程序代码中,类SalesTicket 能够完成打印票据正文的功能,类HeadDecorator 与FootDecorator 分别完成打印票据的台头和脚注的功能。已知该程序运行后的输出结果如下所示,请填补该程序代码中的空缺。这是票据的台头!这是票据正文!这是票据的脚注!------------------------这是票据的台头!
这是票据的脚注!
[Java程序代码]
public class SalesTicket {
public void printTicket() {
System.out.println("这是票据正文!");
}
}
public class Decorator extends SalesTicket{
SalesTicket ticket;
}
}
public class FootDecorator extends Decorator{
public FootDecorator(SalesTicket t) {
(2) ;
}
public void printTicket() {
super.printTicket();
System.out.println("这是票据的脚注!");
}
}
public class Main {
public static void main(String[] args) {
T = new HeadDecorator( (3) );
T. (4) ;
System.out.println("------------------------");
T = new FootDecorator( (5) );
T.printTicket();
}
}
public Decorator(SalesTicket t){
ticket = t;
}
public void printTicket(){
if(ticket != null)
ticket.printTicket();
}
}
public class HeadDecorator extends Decorator{
public HeadDecorator(SalesTicket t) {
(1) ;
}
public void printTicket() {
System.out.println("这是票据的台头!");
super.printTicket();
第4题:
阅读以下说明和Java代码,请回答问题1和问题2。
【说明】
己知类Stock和类cxyjava都定义在cxyjava.java文件中,类Stock的定义中第14行前共有四行出现了错误,将下面代码修改正确并完善后的输出结果为:
0:0
1:23
【Java代码】
01 public class Stock{
02 static {
03 shares = 0;
04 share val = 0.0;
O5 }
06 public Stock(){getData();}
07 public Stock(int n, iht pr=0){
08 shares = n;
09 share val = pr;
10 getData();
11 }
12 public void getData() {
13 System.out.println(shares + ":"+share_val);
14 }
15 private int shares;
16 private int share_val;
17 };
18
19 public class cxyjava{
20 public static void main(String args[]) {
21 Stock a = (1) ;
22 Stock b = new Stock(1,23);
23 //其他无输出代码省略
24 }
25 }
请指出错误所在行号并给出该行修改后的完整结果。
第5题:
阅读以下说明和Java代码,回答问题1和问题2,将解答填写在对应栏内。
【Java代码】
class usethread implements (1) {
int num
usethread(int n){
num=n;
}
public void (2) {
for(int i=0;i<3;i++)
System.out.println("running:"+num);
System.out.println("finished:"+num);
}
public class multhread{
public static void main(String args[]) (3) InterruptedException{
Thread m1=new Thread(new usethread(1));
Thread m2=new Thread(new usethread(2));
m1.start();
m2.start();
m1.join();
m2.join();
}
}
【问题1】
补充完整上面Java代码中(n)处。
【问题2】
写出上面Java代码运行的结果。
第6题:
阅读下列代码
Public class Person{
Static int arr[ ] = new int (10);
Public static void main (String args ) {
System.out.println(arr[9]);
}
}
该代码运行的结果是
A )编译时将产生错误
B )编译时正确,运行时将产生错误
C )输出 0
D )输出空
第7题:
如下两个源程序文件,分别编译后,运行Example.class文件,运行结果为______。
AB.java文件代码如下;
package test;
public class AB
{
int a=60;
public void show()
{
System.out.println(”a=”+a);
}
Example.java文件代码如下:
import test.AB;
class Example
{
public static void main(String args[])
{
AB bj=new AB();
obj.show();
}
}
第8题:
阅读下列代码段,选出该代码段的正确文件名( )。 class A { void methodl() { System.out.println("methodl in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }
A.A.java
B.A.class
C.B.class
D.B.java
第9题:
下列哪个选项的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{ }
第10题:
在下列源代码文件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; } }