网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

【单选题】给出下面的代码段: public class Cell{ int row; int col; int height; int width; public Cell(int row,int col){ this.row=row;this.col=col; } public Cell(int row,int col,int height,int width){ <插入代码> this.height=height; this.width=width; } } 在<插入代码>处写下如下代码,正确的是:

A.Cell(row,col);

B.super(row,col);

C.this.row=row,this.col=row;

D.this(row,col);


参考答案和解析
编译时将产生错误
更多 “【单选题】给出下面的代码段: public class Cell{ int row; int col; int height; int width; public Cell(int row,int col){ this.row=row;this.col=col; } public Cell(int row,int col,int height,int width){ <插入代码> this.height=height; this.width=width; } } 在<插入代码>处写下如下代码,正确的是:A.Cell(row,col);B.super(row,col);C.this.row=row,this.col=row;D.this(row,col);” 相关考题
考题 ●试题二阅读下列程序或函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【函数2.1说明】函数strcmp()是比较两个字符串s和t的大小。若s<t函数返回负数;若s=t函数返回0;若s>t,函数返回正数。【函数2.1】int strcmp(char *s,char *t){ while(*s *t (1) ){s++;t++;}return (2) ;}【程序2.2说明】在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个。【程序2.2】#includestdio.h#define N 100int a[N][N];void main(){ int row ,col,max,min,n;/*输入合法n(<100),和输入n×n个整数到数组a的代码略*/for (row=0;row<n;row++){for(max=a[row][0],col=1;col<n;col++)if( (3) )max=a[row][col];if( (4) )min=max;else if( (5) )min=max;}printf ("The min of max numbers is %d\n",min);}

考题 ( 12 ) “ 图形 ” 类 Shape 中定义了纯虚函数 CalArea() ,“ 三角形 ” 类 Triangle 继承了类Shape ,请 将Triangle 类中的 CalArea 函数补充完整。class Shape{public:virtual int CalArea()=0;}class Triangle: public Shape{public:Triangle{int s, int h}: side(s),height(h) {}【 12 】 { return side*height/2 ; }private:int side;int height;};

考题 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehiele类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将Vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。includeiostream.hclass vehicle{private:int MaxSpeed;int Weight;public://*************found************vehicle(int maxspeed,int weight):——~vehicle{};int getMaxSpeed{return MaxSpeed;}int getWeight{retum Weight;}};//****************found************class bicycle:——public vehicle{private:int Height;public:bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}int getHeight{retum Height;};};//*******************found**************class motorcar:——public vehicle{private:int SeatNum;public:motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}int getSeatNum{return SeatNum;};};//*****************found***************class motorcycle:——{public:motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}};void main{motorcycle a(80,150,100);couta.getMaxSpeedendl;couta.getWeightendl;couta.getHeightendl;couta.getSeatNumendl;}

考题 阅读下列一个支持多线程并发操作的堆栈类代码段 public class MyStack{ private int idx=0; private int[]data=new int[8]; public______void push(int i){ data[idx]=i; idx + +; } …… } 在下画线处应填入的是A.synchronizedB.waitC.blockedD.interrupt

考题 阅读以下说明和JAVA 2代码,填入(n)处。[说明]以下JAVA程序设计了类CSet,使用同一个名称(set)的method来传入数据。仔细阅读[代码6-1)、[代码6-2]和[代码6-3]和相关注释,将程序补充完整。[代码6-1]import java.io.*;class CSet{private int width;private int height;(1)public void set(String color){col=color; //(a)可输入长方形的颜色}public void set (iht w, int h){width=w; //(b)可输入长方形的宽和高height=h;}public void set (String color, int w, int h){col=color; //(c)可输入长方形的颜色、宽和高width=w;height=h;}public void show ( ){System.out.println ("n\长方形的颜色为: "+col);System.out.println ("n\长方形宽为: "+width+" 长方形高为: "+height");}}[代码6-2]public class hw8_3{public static void main (String args[]) throws IOException{intw, h; //声明宽、长变量,并给予赋值String color, k;CSet rect1;rect1=new CSet ( );System.out.print ("\n请输入颜色:: ");color=input ( );System.out.print ("请输入宽度:: ");k=input ( );w=Integer.parseInt (k);System.out.print ("请输入高度:: ");k=input( );h=Integer.parseInt (k);(2)//设置长方形的颜色(3)//设置长方形的宽、高rectl.show ( );(4)//设置长方形的颜色和宽、高rectl.show ( );}[代码6-3]public static String input( ) throws IOException//输入函数{String str;BufferedReader buf;(5)str=buf.readLine ( )return str;}}

考题 在如下源代码文件Test.java中, 哪个是正确的类定义?() 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

考题 使用VC6打开考生文件夹下的工程test42_1,此工程包含一个源程序文件test42_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为:rect area: 12rectb area: 30源程序文件test42_1.cpp清单如下:include <iostream.h>class CRectangle{/***************** found *****************/int *width, height;public:CRectangle (int,int);~CRectangle ();int area (void) {return (*width * *height);}};CRectangle::CRectangle (int a, int b){width = new int;height = new int;/***************** found *****************/width = a;*height = b;}CRectangle::~CRectangle (){delete width;delete height;}/***************** found *****************/void main (){CRectangle rect (3,4), rectb (5,6);cout << "rect area: "<< rect.area() << endl;cout << "rectb area: "<< rectb.area() << endl;return 0;}

考题 给出下列代码,如何使成员变量m被方法fun( )直接访问?Class Test{private int m;public static void fun( ){} }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static int mD.将private int m改为int m

考题 指出下面程序段中的错误,并说明出错原因【 】。class Location {int X, Y=20;protected:int zeroX, zeroY;int SetZero(int ZeroX, iht ZeroY);private:int length, height;public:float radius;void init(int initX,int initY);int GetX();Int GetY();};

考题 类Test定义如下,将下列______方法插入③行处是不合法的。 ( )①public class Test{②public float Method(float a,float b){}③④}A.public float Method(float a,float b,float c){}B.public float Method(float c,float d){}C.public int Method(int a,int b){}D.private float Method(int a,int b,int c){}

考题 给出下列代码,如何使成员变量m被方法fun( )直接访问? class Test{ private int m; public static void fun( ){ … } }A.将private int m改为protected int mB.将private int m改为public int mC.将private int m改为static iD.将private int m改为int m

考题 在下列源代码文件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; } }

考题 阅读下面实现堆栈类并发控制的部分代码 public class DataStack{ private int idx=0; private int[]data=new int[8]; public void push(int i){ . ________________{ data[idx]=i; idx + +; } } } …… } 在程序下画线处填入正确选项是A.synchronizedB.synchronized(this)C.synchronized()D.synchronized(idx)

考题 fun函数的功能是首先对a所指的N行N列的矩阵找出各行中最大的数,再求这N个最大值中最小的那个数作为函数值返回,请填空。#include stdio.h#define N 100int fun(int(*a)[N]){ int row,col,max,min; for(row=0;rowN;row++) { for(max=a[row][0],col=1;colN;col++) if() max=a[row][col]; if(row==0) min=max; else if() min=max; } return min;}

考题 阅读以下说明和JAVA 2代码,填入(n)处的。[说明]以下JAVA程序实现了在接口interface iShape2D的定义和应用,仔细阅读代码和相关注释,将程序补充完整。[代码6-1]interface iShape2D //定义接口{(1)(2)}(3)//实现CRectangle类{int width, height;(4) CRectangle (int w,int h) {width=w;height=h;}public void area ( ){ //定义area( )的处理方式System. out.println ("area="+width*height);}}(5)//实现CCircle类{double radius;(6) CCircle (double r) {radius=r;}public void area ( ) { //定义area( )的处理方式System.out.println ("area="+pi*radius*radius);}}[代码6-2]public class app10_4{public static void main(String args[]){CRectangle rect=new CRectangle (5,10);rect.area ( ); //调用CRectangle类里的area ( ) methodCCircle cir=new CCircle (2.0);cir.area ( ); //调用CCircl类里的area ( ) method}}

考题 有以下程序:include using namespace std;class A{private: int x,y;public: void se 有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。A.8B.4C.35D.70

考题 以下fun函数的功能是在N行M列的整型二维数组中,选出一个最大值作为函数值返回,请填空。(设M,N已定义)int fun(int a[N][M]){int i,j,row=0,col=0;for(i=0;iN;i++)for(j=0;jM;j++)if(a[i][j]a[row][col])(row=i;col=j;)return(_____);}

考题 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 includelostream {tout——endl;} class CRectangle:public CPolygon{ CReangle(int w,int h):width(w),height(h){} int area(void){return(width *height);} class CTriangle:public CPolygon{ int length;//三角形一边长 int height;//该边上的高 public: CTriangle(int l,int h):length(1),height(h){} //*********found********* int area(void){return(——)/2;} }; int main{ CRectangle rect(4,5); CTriangle trgl(4,5); //*********found********* ______ *ppolyl,* ppoly2; ppolyl=rect; ppoly2=trgl; ppolyl-printarea; ppoly2-printarea; retun 0;

考题 类Test定义如下,将下列哪个方法插入③行处是不合法的( )?① public class Test{② public float Method(float a,float B) { }③ ______④ }A.public float Method(float a,float b,float C) { }B.public float Method(float c,float d){ }C.public int Method(int a,int B) { }private float Method(int a,int b,int C) { }D.private float Method(int a,int b,int C) { }

考题 请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。[题目要求]生成下面左边图形界面,单击图中的New按钮,弹出如右图所示的对话框。源程序:import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Java_3 {public static void main(String[] args) {MulticastFrame. frame=new MulticastFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();}}class MulticastFrame. extends JFrame. {public MulticastFrame() {setTitle("MulticastTest");setSize(WIDTH,HEIGHT);MulticastPanel panel=new MulticastPanel();Container contentPane=getContentPane();contentPane.add( (1) );}public static final int WIDTH=300;public static final int HEIGHT=200;}class MulticastPanel extends JPanel }public MulticastPanel() {JButton newButton=new JButton("New");add(newButton);ActionListener newListener=new ActionListener() {public void actionPerformed(ActionEvent event) {makeNewFrame();}};newButton.addActionListener(newListener);closeAllButton=new JButton("Close all");add(closeAllButton);}private void makeNewFrame() {final BlankFrame. frame=new BlankFrame();frame.show();ActionListener closeAllListener=new ActionListener() {public void actionPerformed(ActionEvent event) {frame. (2) (); //使窗口隐藏或消除}};closeAllButton.addActionListener( (3) );}private JButton closeAllButton;}Class BlankFrame. extends JFrame. {public BlankFrame() {(4) ++;setTitle("Frame"+counter);setSize(WIDTH,HEIGHT);setLocation(SPACING*counter,SPACING*counter);}public static final int WIDTH=200;public static final int HEIGHT=150;public static final int SPACING=30;private static int counter=0;}

考题 在下列源代码文件Test.java中, ( )是正确的类定义。A.public class test{B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }C.public class Test extends T1,T2{D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}

考题 本题的功能是在文本域面板中添加一个带有行数的面板。窗口中有一个文本域,在文本域的左侧有一个带有数字的面板,该面板上的数字指示着文本域中的行数。import javax.swing.*;import javax.swing.event.*;import java.awt.*;public class java3 extends JFrame{public static JTextPane textPane;public static JScrollPane scrollPane;JPanel panel;public java3(){super("java3()");panel=new JPanel();panel.setLayout(new BorderLayout());panel.setBorder(BorderFactory.createEmptyBor-der(20,20,20,20));textPane=new JTextPane();textPane.setFont(new Font("monospaeed",Font.PLAIN,12));scrollPane=new JScrollPane(textPane);panel.add(scrollPane);scrollPane.setPreferredsize(new Dimension(300,250));setContentPane(panel);setCloseOperation(JFrame.EXIT_ON_CLOSE);LineNumber lineNumber=new LineNumber();scrollPane.setRowHeaderView(lineNumber);}public static void main(String[]args){java3 ttp=new java3();ttp.pack();ttp.setVisible(true);}}class LineNumber extends JTextPane{private final static Color DEFAULT_BACK-GROUND=Color.gray;private final static Color DEFAULT_FORE-GROUND=Color.black;private final static Font DEFAUl。T—FONT=newFont("monospaced",Font.PLAIN,12);private final static int HEIGHT=Integer.MAX_VALUE-1000000;private final static int MARGIN=5;private FontMetrics fontMetrics;private int lineHeight;private int currentRowWidth;private JComponent component;private int componentFontHeight;private int componentFontAscent;public LineNumber(JComponent component){if(component= =null){setBackground(DEFAULT_BACKGROUND);setForegroun"DEFAULT_FOREGROUND);setFont(DEFAULT FONT);this.component=this;}else{setBaekground(DEFAULT_BACKGROUND);setForeground(component.getForeground());setFont(component.getFont());this.component=component;}componentFontHeight=component.getFontMet-rics(component.getFont()).getHeight();componentFontAscent=component.getFontMet-ries(component.getFont()).getAscent();setPreferredWidth(9999);}public void setPreferredWidth(int row){int width=fontMetrics.stringWidth(String.val-ueOf(row));if(currentRowWidth<width){currentRowWidth=width;setPreferredSize(new Dfimension(2 * MARGIN+width,HEIGHT));}}public void setFont(Font font){super.setFont(font);fontMetrics=getFontMetrics(getFont());}public int getLineHeight(){if(hneHeight= =0)return componentFontHeight;elsereturn lineHeight;}public void setLineHeight(int lineHeight){if(hneHeight>0)this.lineHeight=lineHeight;}public int getStartOffset(){return component.getlnsets().top+component-FontAscent;}public void paintComponent(Graphics g){int lineHeight=getLineHeight();int startOffset=getStartOffset();Rectangle drawHere=g.getClipBounds();g.setColor(getBackground());g.fillRect(drawHere.x,drawHere.Y,drawHere.width,drawHere.height);g.setColor(getForeground());int startLineNumber=(drawHere.y/line-Height)+1;int endLineNUmber = startLineNumber+(drawHere.height/lineHeight);int start=(drawHere.Y/hneHeight)*line-Height+startOffset;for(int i=startLineNumber;i<=endLineN-umber;i++){String lineNumber=String.valueOf(i);int width=fontMetrics.stringWidth(lineNumber);g.drawstring(lineNumber,MARGIN+current-RowWidth-width,start);start+=lineHeight:}setPreferredWidth(endLineNumber);}}

考题 在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )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 Ti,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; } }

考题 在注释//Start For loop 处要插入哪段代码可实现根据变量i的值定位数组ia[]的元素?public class Lin{public void amethod(){int ia[] = new int[4];//Start For loop{ia[i]=i;System.out.println(ia[i]);}}} A. for (int i=0; iB. for (int i=0; iC. for (int i=1; iD. for (int i=0; i

考题 给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } A、public int cal(int x,int y,float z){return 0;}B、public int cal(int x,int y,int z){return 0;}C、public void cal(int x,int z){}D、public viod cal(int z,int y,int x){}

考题 组件的setSize()方法签名正确的是哪项?()A、 setSize(int width,int height)B、 setSize(int x,int y,int width,int height)C、 setSize(Dimension dim)D、以上皆不是

考题 多选题组件的setSize()方法签名正确的是哪项?()AsetSize(int width,int height)BsetSize(int x,int y,int width,int height)CsetSize(Dimension dim)D以上皆不是

考题 多选题给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A }Apublic int cal(int x,int y,float z){return 0;}Bpublic int cal(int x,int y,int z){return 0;}Cpublic void cal(int x,int z){}Dpublic viod cal(int z,int y,int x){}