问答题(2014年春程序员软考)

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。

下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。

enum Note{/*枚举各种音调*/

MIDDLE_C, C_SHARP, B_FLAT;//其他略

}

interface Instrument{/*接口,乐器*/

__(1)__;//p1ay方法接口

void adjust();// adjust方法接口

}

class Wind __(2)__{

public void play(Note n){System. out. println("Wind. play() "+ n);}

public void adjust(){System. out. println("Wind. adjust ()");}

}

/*类 Percussion和 Stringed实现代码略*/

class Brass __(3)__{

public void play(Note n){System. out. println("Brass. play()"+ n);}

public void adjust(){System. out. println("Brass. adjust ()");}

}

class Woodwind extends Wind{

public void play(Note n){System. out. printin("Woodwind. play()"+ n);}

}

public class Music{

void tune(Instrument i){i.play(Note. MIDDLE_C);}

void adjust(Instrument i){i.adjust();}

void tuneAll(__(4)__ e){

for(Instrument i : e){

adjust(i);

tune (i);

}

}

public static void main(String[] args){

Music music=__(5)__ Music();

Instrument[] orchestra =I new Wind(), new Woodwind ()};

music. tuneAll(orchestra);

}

}

Wind. adjust ()

Wind. play () MIDDLE_C

Wind. adjust()

Woodwind. play() MIDDLE_C

参考答案

关键词

接口;对象;子类;void;public;数组;java;参数;new;类;

子类在原有父类接口的前提下,用适合于自己要求的实现去置换父类中的相应实现称为【 】。

以下关于解释器运行程序的叙述中,错误的是【 】

在编译器和解释器的工作过程中,【 】是指对高级语言源程序进行分析以识别出记号的过程。

阅读以下说明和Java程序,填补代码中的空缺(1)~(6)。很多依托扑克牌进行的游戏都要先洗牌。下面的Java代码运行时先生成一副扑克牌,洗牌后再按顺序打印每张牌的点数和花色。import java.util. List;import java.util. Arrays;import java. util. Collections;class Card{//扑克牌类 public static enum Face{Ace, Deuce, Three, Four, Five, Six,Seven, Eight, Nine, Ten, Jack, Queen, King};//枚举牌点 public static enum Suit{ Clubs, Diamonds, Hearts, Spades};//枚举花色 private final Face face; private final Suit suit; public Card( Face face, Suit suit ){ __(1)__ face = face; __(2)__ suit= suit; } public Face getFace() {return face;} public Suit getSuit() {return suit; } public String getCard(){//返回String来表示一张牌 return string. format( "%s,%s", facer,suit ); }}class DeckOfCards{//牌桌类 pivate List< Card> list;//声明List以存储牌 public DeckOfCards (){//初始化牌桌并进行洗牌 Card[] deck=new Card[52]; int count=0;//牌数 //用Card对象填充牌桌 for(Card.Suit suit : Card.Suit.values()){ for(Card.Face face : Card.Face.values ()){ __(3)__=new Card(face,suit); } } list=Arrays.asList( deck ); Collections. shuffle( list ); //洗牌 public void printCards (){//按4列显示52张牌 for( int i=0; i<list.size(); i++) System. out. printf("%-19s%s",list.__(4)__,((i+1)%4==0)?"\n":""); }}public class Dealer { public static void main( String[] args){ DeckofCards player=__(5)__; __(6)__ printcards(); }}

在面向对象方法中,对象之间通过发送【 】进行通信,当其发送给某个对象时,包含要求接收对象去执行某些活动的信息。

在面向对象方法中,继承用于【 】。

通过继承关系创建的子类【 】。

对象、类、继承和消息传递是面向对象的4个核心概念。其中对象是封装【 】的整体。

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

简述Unix/Linux系统中使用socket库编写服务器端程序的流程。

说说Java中String、StringBuffer、StringBuilder的主要区别。

结合自己的理解说说什么是多态?Java是如何实现多态的?

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C

对部分乐器进行建模,其类图如图所示,包括,乐器( Instrument)、管乐器(wind)、打击乐器( Percussion)、弦乐器( Stringed)、木管乐器( Woodwind)、铜管乐器( Brass)。下面是实现上述设计的Java代码,其中音乐类( Music)使用各类乐器( Instrument)进行演奏和调音等操作。enum Note{/*枚举各种音调*/ MIDDLE_C, C_SHARP, B_FLAT;//其他略}interface Instrument{/*接口,乐器*/ __(1)__;//p1ay方法接口 void adjust();// adjust方法接口}class Wind __(2)__{ public void play(Note n){System. out. println("Wind. play() "+ n);} public void adjust(){System. out. println("Wind. adjust ()");}}/*类 Percussion和 Stringed实现代码略*/class Brass __(3)__{ public void play(Note n){System. out. println("Brass. play()"+ n);} public void adjust(){System. out. println("Brass. adjust ()");}}class Woodwind extends Wind{ public void play(Note n){System. out. printin("Woodwind. play()"+ n);}}public class Music{ void tune(Instrument i){i.play(Note. MIDDLE_C);} void adjust(Instrument i){i.adjust();} void tuneAll(__(4)__ e){ for(Instrument i : e){ adjust(i); tune (i); } } public static void main(String[] args){ Music music=__(5)__ Music(); Instrument[] orchestra =I new Wind(), new Woodwind ()}; music. tuneAll(orchestra); }}Wind. adjust ()Wind. play () MIDDLE_CWind. adjust()Woodwind. play() MIDDLE_C