网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
阅读以下代码: public class Test{ public static void main(){ System.out.println(“x=”+x); } } 请问,代码运行的结果是?()
- A、 x
- B、 x=x
- C、 “x=”+5
- D、 编译报错
参考答案
更多 “ 阅读以下代码: public class Test{ public static void main(){ System.out.println(“x=”+x); } } 请问,代码运行的结果是?() A、 xB、 x=xC、 “x=”+5D、 编译报错” 相关考题
考题
试题八(共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();
考题
阅读下列代码段,选出该代码段的正确文件名( )。 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.javaB.A.classC.B.classD.B.java
考题
阅读下列代码段,选出该代码段的正确文件名( )。 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.javaB.A.classC.B.classD.B.java
考题
阅读下列代码 public class Test 2005{ public static void main(String args[]){ System.out.println(~(0xa5)0xaA.0xa5B.10C.0x50D.0xaa
考题
阅读下列代码 public class Test 2005{ public static void main(String args[]){ System.out.println((3>2)?4:5); } } 其运行结果是A.2B.3C.4D.5
考题
阅读下列代码 public class Test{ public static void main(String args[]){ System.out.println(89>>1); } } 其运行结果是A.44B.45C.88D.90
考题
阅读下列代码 public class { public static void main(String args[]){ double d=12.3; Decrementer dec=new Decrementer(); dec. decrement(D) ; System. out. println(D) ; } } class Decrementer{ public void decrement(double decMe){ decMe=decMe-1.0; } } 代码执行后输出结果是A.12.3B.11.3C.13.3D.-1.0
考题
阅读下列代码段 abstract class Person{ public Person(String n){ name=n; } public______String getDescription(); public String getName(){ } private String name; } 在下画线处应填入的修饰符是A.staticB.abstractC.protectedD.final
考题
阅读下列代码 public class Test{ String s="One World One Dream"; public static void main(String args[]){ System. out. println(s); } } 其运行结果是A.argsB.One World One DreamC.sD.编译时出错
考题
( 21 )阅读下列代码public class Test2005{public static void main(String args[]){System.out.println((32) ? 4 : 5) ;}}其运行结果是A ) 2B ) 3C ) 4D ) 5
考题
( 22 )阅读下列代码public class Test{public static void main(String args[]){System.out.println(891) ;}}其运行结果是A ) 44B ) 45C ) 88D ) 90
考题
( 8 )阅读下列代码public class Test2{public static void main(String args[]){System.out.println(5/2);}}其执行结果是 【 8 】 。
考题
阅读以下说明和C++代码,填入(n)处。[说明]以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。[代码5-1]include<iostream.h>define PI 3.14159class shape {//基类protected:(1);public:(2);(3);};[代码5-2]class rectangle: public shape {public:rectangle (int x2,int y2,int r2): (4) {};double area ( ) {return x*y; };};class circle: public shape {public:circle (int x3,int y3,int r3):(5){};double area ( ) {return r*r*PI; };};[代码5-3]void main ( ){rectangle r (10,20,0);circle c (0,0,30);shape (6);cout<<"长方形面积="<<s1->area ( ) <<endl;cout<<"圆形面积="<<s2->area ( ) <<endl;}[运行结果]长方形面积=200圆形面积=2827.43
考题
阅读下面代码 abstract class Person { public Person(String n) { name=n; } public______String getDescription(); public String getName() { return name; } private String name; } 在下画线处应填入的修饰符是A.staticB.abstractC.protectedD.final
考题
阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是A.argsB.World One DreamC.sD.编译时出错
考题
阅读下面代码: public class Test2005 { public static void main(String args[]) { System.out.println((3>2)? 4:5); } } 其运行结果是A.2B.3C.4D.5
考题
在下列源代码文件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; } }
考题
写出下列程序代码运行的结果【】。 include class A{public:virtual void disp() {cout
写出下列程序代码运行的结果【 】。include<iostream.h>class A{public:virtual void disp() {cout<<" calss A!" <<(end1;}}:class B: public A{public:void disp() {cout<<" class B! " <<end1:}};class C: public A{public:void disp() {cout<<"class C! " (<end1;}};void main() {A a, *ptr;B b;C c;a. disp();b. disp();c. disp();ptr=b;ptr->disp();ptr=c;ptr->disp():}
考题
请阅读以下一段程序,并给出答案。class A{public:A(){ doSth() }virtual void doSth(){ printf("I am A");}}class B:public A{public:virtual void doSth(){ printf("I am B");}}B b;执行结果是什么?为什么?
考题
阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}
考题
试题五(共 15 分)阅读以下说明和 Java 程序,填补代码中的空缺,将解答填入答题纸的对应栏内。【说明】以下 Jave 代码实现一个简单客户关系管理系统(CrM) 中通过工厂 (Customerrfactory )对象来创建客户(Customer) 对象的功能。客户分为创建成功的客户 (realCustomer) 和空客户(NullCustomer) 。空客户对象是当不满足特定条件时创建或获取的对象。类间关系如图 5-1 所示。【Java 代码】Abstract class Customer﹛Protected String name;()boolean isNil()()String getName();﹜ Class realCustomer ()Customer﹛Public realCustomer(String name )﹛ return false; ﹜﹜ Class NullCustomer()Customer﹛Public String getName()﹛ return ″Not Available in Customer Database″; ﹜Public boolean isNil()﹛ return true; ﹜﹜ class Customerfactory {public String[] names = {"rob","Joe","Julie"};public Customer getCustomer(String name) {for (int i = 0; i getCustomer();Crs->getCustomer();Delete crs;return();﹜/*程序输出为:CustomerrobNot Available ini Customer DatabaseJulieNot Available in Customer Database
考题
阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。
[说明]
某应急交通控制系统(TraficControlSystem)在红灯时控制各类车辆(Vehicle)的通行,其类图如下图所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规则通行。
下面的Java代码实现以上设计,请完善其中的空缺。
[Java代码]abstract class Vehicle{public Vehicle(){ }abstract void run();};interface Emergency{ ______; ______;};class Car extends Vehicle{public Car(){ }void run(){ /*代码略*/ }};Class Truck extends Vehicle{public Truck(){ }void run() { /*代码略*/ }};class PoliceCar ______ {boolean isEmergency= false;public PoliceCar(){ }public PoliceCar(boolean b) {this.isEmergency=b; }public boolean isEmergent(){ return ______ }public void runRedLight(){ /*代码略*/ }};/*类Ambulance、FireEngine实现代码略*/public class TraficControlsystem { /*交通控制类*/private Vehicle[]V=new Vehicle[24];int numVehicles;public void control(){for {int i=0; i<numVehicles; i++){if(V[i]instanceof Emergency}else______. run();}}void add(Vehicle vehicle){ v[numVehicles++]=vehicle;}/*添加车辆*/void shutDown(){/*代码略*/}public static void main(String[]args){TraficC0ntrolSystem tcs=new TraficControlSystem();tcs.add(new Car());tcs.add(new PoliceCar());tcs.add(new Ambulance());tcs.add(new Ambulance(true));tcs.add(new FireEngine(true));tcs.add(new Truck());tcs.add(new FireEngine());tcs.control();tcs.shutDown();}}
考题
阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】某软件公司欲开发一款汽车竞速类游戏,需要模拟长轮胎和短轮胎急刹车时在路面上留 下的不同痕迹,并考虑后续能模拟更多种轮胎急刹车时的痕迹。现采用策略(Strategy)设计模式来实现该需求,所设计的类图如图 5-1 所示。
【Java代码】import java.util.*; interface BrakeBehavior{public (1) ;/*其余代码省略*/}class LongWheelBrake implements BrakeBehavior{public void stop(){System.out.println("模拟长轮胎刹车痕迹! ");}/*其余代码省略*/}class ShortWheelBrake implements BrakeBehavior {public void stop(){System.out.println("模拟短轮胎刹车痕迹! ");}/*其余代码省略 */}abstract class Car{protected (2) wheel;public void brake(){ (3) ;}/*其余代码省略*/}class ShortWheelCar extends Car {public ShortWheelCar(BrakeBehavior behavior){(4) ; } /*其余代码省略*/}class StrategyTest{public static void main(String[]args){BrakeBehaviorbrake =new ShortWheelBrake();ShortWheelCar car1= new ShortWheelCar(brake);car1. (5) ;}}
考题
阅读下列说明和 Java 代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图 6-1 所示为其类图。
阅读下列说明和C++代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
???? 生成器(Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图5-1所示为其类图。
?
【C++代码】
#include
#include
using namespace std;
class Product {
private:?
string partA, partB;
public:?
Product() {?? }? ?
void setPartA(const string}
???? void setPartB(const string}? ?
//? 其余代码省略
};
class Builder {
public:? ? ??
(1)??
;?
virtual void buildPartB()=0;? ? ?
(2)??
;
};
class ConcreteBuilder1 : public Builder {
private:?
Product*?? product;
public:
ConcreteBuilder1() {product = new Product();???? }
void buildPartA() {????? (3)???? ("Component
A"); }?
void buildPartB() {????? (4)???? ("Component
B"); }??
Product* getResult() { return product; }
//? 其余代码省略
};
class ConcreteBuilder2 : public Builder {? ??? ? ? ?
/*??? 代码省略??? */
};
class Director {
private:? ??
Builder* builder;
public:??
Director(Builder* pBuilder) { builder= pBuilder;}? ??
void construct() {
????????????????? (5)???? ;
?????????????? //? 其余代码省略? ?
}??
//? 其余代码省略
};
int main() {? ? ??
Director* director1 = new Director(new ConcreteBuilder1());? ?
director1->construct();? ? ??
delete director1;? ? ?
return 0;
【Java代码】
import jav(6)A.util.*;
class Product {? ? ? ?
private String partA;? ? ? ?
private String partB;? ? ? ??
public Product() {}? ? ??
public void setPartA(String s) { partA = s; }? ? ? ?
public void setPartB(String s) { partB = s; }
}
interface Builder {? ?
public?????? (1)???? ;? ??
public void buildPartB();? ? ??
public?????? (2)???? ;
}
class ConcreteBuilder1 implements Builder {? ? ? ?
private Product product;? ? ? ?
public ConcreteBuilder1() { product = new Product();?? }? ? ? ??
public void buildPartA() {????????
(3)??
("Component A"); }
public void buildPartB() {???? ????(4)?? ("Component B"); }? ? ??
public Product getResult() { return product;}
}
class ConcreteBuilder2 implements Builder {?? ? ? ? ?
//? 代码省略
}
class Director {? ? ? ?
private Builder builder;? ? ? ?
public Director(Builder builder) {this.builder = builder; }
public void construct() {
? ? ? ? ? ? ? ? ? (5)???? ;
? ? ? ? ? ? ? //? 代码省略? ? ??
}
}
class Test {? ? ??
public static void main(String[] args) {
???????????????? Director director1 = new
Director(new ConcreteBuilder1());
???????????????? director1.construct();? ? ? ??
}
考题
下列代码正确的是哪项?() A、 public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }B、 public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }C、 public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }D、 public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
考题
单选题下列代码正确的是哪项?()A
public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }B
public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }C
public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }D
public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
考题
单选题阅读以下代码: public class Test{ public static void main(){ System.out.println(“x=”+x); } } 请问,代码运行的结果是?()A
xB
x=xC
“x=”+5D
编译报错
热门标签
最新试卷