阅读下列代码public class Test{public static void main(String args[]){ System.out.println(8
阅读下列代码 public class Test{ public static void main(String args[]){ System.out.println(89>>1); } } 其运行结果是
A.44
B.45
C.88
D.90
阅读下列代码 public class Test{ public static void main(String args[]){ System.out.println(89>>1); } } 其运行结果是
A.44
B.45
C.88
D.90
阅读下列代码 public class Test2005{ public static void main(String args[]){ String s="Test"; switch(s){ case"Java":System.out.print("Java"); break; case"Language":System.out.print("Lan- guage"); break; case"Test":System.out.print("Test"); break; } } } 其运行结果是()。
A.Java
B.Language
C.Test
D.编译时出错
试题六(共15分)
阅读下列说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图6-1所示的类图。
【java代码】
class invoice{
public void printInvoice(){:
System.out.println ("This is the content of the invoice!");
}
}
class Decorator : extends Invoice {
protected Invoice ticket;
public Decorator(lnvoice t){
ticket = t;
}
public void printinvoice(){
if(ticket != NULL)
(1);
}
}
class FootDecorator extends Decorator{
public FootDecorator(lnvoice t){
super(t);
}
public void printinvoice (){
Systent.out.println("This is the header of the invoice! ");
(2) ;
}
}
class FootDecorator extends Decorator {
public FootDecorator(invoice t):{
super(t);
}
public void printlnvoice(){
(3) ;
Systent.out.println("This is the header of the invoice! ");
}
}
Class test {
public static void main(string[] args){
Invoice t =new invioce();
Invoice ticket;
Ticket= (4) ;
Ticket. Printinvoice();
Systent.out.println(“--------------“)
Ticket= (5) ;
Ticket. Printinvoice();
}
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
试题五(共15分)
阅读下列说明和C++-代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
【说明】
某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。
【C++代码】
include <iostream>
using namespace std;
class invoice{
public:
(1) {
cout《 "This is the content of the invoice!"《 endl;
}
};
class Decorator : public invoice {
Invoice *ticket;
public:
Decorator(lnvoice *t) { ticket = t; }
void printinvoice(){
if(ticket != NULL)
(2);
}
};
class HeadDecorator : public Decorator{
public:
HeadDecorator(lnvoice*t): Decorator(t) { }
void printinvoice0 {
cout《 "This is the header of the invoice! "<< endl;
(3) ;
}
};
class FootDecorator : public Decorator{
public:
FootDecorator(invoice *t): Decorator(t) { }
void printlnvoice() {
(4) ;
cout《 "This is the footnote of the invoice!"《 endl;
}
};
int main(void) {
Invoice t;
FootDecorator f(&t);
HeadDecorator h(&f);
H.printlnvoice();
cout< < “_____”< < endl;
FootDecorator a(NULL);
HeadDecorator b((5) );
B.printinvoice();
return 0;
}
程序的输出结果为:
This is the header of the invoice!
This is the content of the invoice!
This is the footnote of the invoice!
----------------------------
This is the header of the invoice!
This is the footnote of the invoice!
阅读下列代码段 abstract class Person{ public Person(String n){ name=n; } public______String getDescription(); public String getName(){ } private String name; } 在下画线处应填入的修饰符是
A.static
B.abstract
C.protected
D.final
阅读下面程序 1 public class Try extends Thread{ 2 public static void main(String args[]){ 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j){ 8 int i=0; 9 while(i<5){ 10 System.out.println(“祝你成功!”); 11 i++; 12 } 13 } 14 } 该程序要求打印5行“祝你成功!”,必须改正程序中的某行代码,程序才能完成。选择正确的修改是
A.将第1行的extends Thread改为implements Runnable
B.将第3行的new Try()改为new Thread()
C.将第4行t.start()改为start(t)
D.将第7行的public void run(int j)改为public void run()
阅读下面程序 1 public class Try extends Thread{ 2 public static void main(String args[]){ 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j){ 8 int i=0; 9 while(i<5){ 10 System.out.println(“祝你成功!”); 11 i++; 12 } 13 } 14 } 该程序要求打印5行“祝你成功!”,必须改正程序中的某行代码,程序才能完成。选择正确的修改是
A.将第1行的extends Thread改为implements Runnable
B.将第3行的new Try()改为new Thread()
C.将第4行t.start()改为start(t)
D.将第7行的public void run(int j)改为public void run()
阅读下列代码 public class Test 2005{ public static void main(String args[]){ Strings="Test"; switch(s){ case "Java":System.out.print("Java"); break; case "Language":System.out.print("Language"); break; case "Test":System.out.ptint("Test"); break; } } } 其运行结果是
A.Java
B.Language
C.Test
D.编译出错
阅读下面程序 1 public class Try extends Thread { 2 public static void main(String args[]) { 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j) { 8 int i=0; 9 while(i<5) { 10 System.out.println("祝你成功!"); 11 i++: 12 } 13 } 14 } 该程序若能打印5行“祝你成功!”,必须改正程序中的某行代码,选择正确的修改是
A.将第1行的extends Thread改为implements Runnable
B.将第3行的new Try()改为new Thread()
C.将第4行的t.start()改为start(t)
D.将第7行的public void run(int j)改为public void run()
阅读下列一个支持多线程并发操作的堆栈类代码段 public class MyStack{ private int idx=0; private int[]data=new int[8]; public______void push(int i){ data[idx]=i; idx + +; } …… } 在下画线处应填入的是
A.synchronized
B.wait
C.blocked
D.interrupt
(19 )阅读下列代码
public class Test2005{
public static void main(String args[]){
String s= ″ Test ″ ;
Switch(s){
case ″ Java ″ : System.out.print(″ Java ″ ) ;
break ;
case ″ Language ″ : System.out.print(″ Language ″ ) ;
break ;
case ″ Test ″ : System.out.print(″ Test ″ ) ;
break ;
}
}
}
其运行结果是
A ) Java
B ) Language
C ) Test
D )编译出错