Java认证考试

package sun.scjp;  public enum Color { RED, GREEN, BLUE }  package sun.beta;  // insert code here  public class Beta {  Color g = GREEN;  public static void main( String[] argv)  { System.out.println( GREEN); }  }  The class Beta and the enum Color are i

题目

package sun.scjp;  public enum Color { RED, GREEN, BLUE }  package sun.beta;  // insert code here  public class Beta {  Color g = GREEN;  public static void main( String[] argv)  { System.out.println( GREEN); }  }  The class Beta and the enum Color are in different packages.  Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile?()

  • A、 import sun.scjp.Color.*;
  • B、 import static sun.scjp.Color.*;
  • C、 import sun.scjp.Color; import static sun.scjp.Color.*;
  • D、 import sun.scjp.*; import static sun.scjp.Color.*;
  • E、 import sun.scjp.Color; import static sun.scjp.Color.GREEN;
如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

对于这样的一个枚举类型:

enum Color:byte{

Red,

Green,

Blue,

Orange

}

string[] ss=Enum.GetNames(typeof(Color));

byte[] bb=Enum.GetValues(typeof(Color));

试写一段程序显示出枚举类型中定义的所有符号名称以及它们对应的数值。


正确答案:
 

第2题:

本题的功能是用按钮来控制文本框中文本的颜色。窗口中有两个带有文字标题的面板“Sample text”和“Text color control”,窗口的底部还有一个复选按钮“Disable changes”。在“Sample text”面板中有一个带有字符串的文本框,而在“Text color control”面板中有三个按钮:“Black”、“Red”和“Green”,并且每个按钮上都有一个对应颜色的圆。单击任意按钮,文本框中的文本变成对应的颜色,如果选中“Disable changes”复选项,则三个颜色按钮变为不可用,如果取消选中复选项,则三个按钮变为可用。

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class java3 extends JFrame{

private JPanel upper,middle,lower;

private JTextField text;

private JButton black,red,green;

private JCheckBox disable;

public java3(String titleText){

super(titleText);

addWindowListener(new WindowAdapter(){

public void

windowClosing(WindowEvent e){

System.exit(0);

}

}

);

upper=new JPanel();

upper.setBorder(BorderFactory.ereateTitledBor-

der("Sample text"));

upper.setlayout(new BorderLayout());

text=new JTextField("Change the color of this

text"):

upper.add(text,BorderLayout.CENTER);

middle=new JPanel();

middle.setBorder(BorderFactory.createTitledBor-

der("Text color control"));

middle.setLayout(new FlowLayout(FlowLayout.

CENTER)):

black=new JButton("Black",new ColorIcon

(Color.black));

black.addActionListener( new ButtonListener

(Color.black));

middle.add(black);

red=new JButton("Red",new ColorIcon(Col-

or.red));

red.addActionListener(new ButtonListener(Col-

or.red));

middle.add(red);

green=new JButton("Green",new ColorIcon

(Color.green));

green.addActionListener(new ButtonListener

(Color.green));

middle.add(green);

lower=new JPanel();

lower.setLayout(new FlowLayout(FlowLayout.

RIGHT));

disable=new JCheckBox("Disable changes"):

disable.addItemListener(new ItemListener()(

public void itemStateChanged(ItemEvent e){

boolean enabled

=(e.getStateChange()

= =ItemEvent.DESELECTED):

black.setEnabled(enabled);

red.setEnabled(enabled);

green.setEnabled(enabled);

}

}

);

lower.add(disable);

Container cp=getContentPane();

cp.add(upper,BorderLayout.NORTH);

cp.add(middle,BorderLayout.CENTER);

cp.add(10wer,BorderLayout.SoUTH);

pack();

setVisible(true);

}

class ButtonListener extends ActionListener{

private Color c;

public ButtonListener(Color c){

this.c=c;

}

public void actionPerformed(ActionEvent e){

text.setForeground(c);

}

}

class ColorIcon implements Icon{

private Color c;

private static final int DIAMETER=10;

public ColorIcon(Color c){

c=c;

}

public void paintlcon(Component cp,Graphics g,

int x,int y){

g.setColor(c);

g.fillOval(X,y,DIAMETER,DIAMETER);

g.setColor(Color.black);

g.drawOval(x,y,DIAMETER,DIAMETER);

}

public int getlconHeight(){

return DIAMETER;

}

public int getlconWidth(){

return DIAMETER;

}

}

public static void main(String[]args){

new java3("advance");

}

}


正确答案:
第1处:upper.setLayout(newBorderLayout())第2处:classButtonListenerimplementsActionListener第3处:this.c=c【解析】第一处令面板upper采用BorderLayout布局。第二处是要求类ButtonListener实HActionListener接口,达到通过按钮改变字体颜色的目的。第三处是设置按钮前圆形的颜色。

第3题:

设有说明var color:(red,green,yellow,blue);a:boolean;下面语句正确的是( )。

Aolor:=‘green‘;

Bwriteln(green);

Cwriteln(color);

Da:=color=red;


正确答案:D

第4题:

public class Test {   public static void main (String args) {  string foo = “blue”;  string bar = foo;   foo = “green”;   System.out.printIn(bar);   }   }   What is the result?()  

  • A、 An exception is thrown.
  • B、 The code will not compile.
  • C、 The program prints “null”
  • D、 The program prints “blue”
  • E、 The program prints “green”

正确答案:D

第5题:

阅读以下说明和 Java 代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 设计 RGB 方式表示颜色的调色板,进行绘图。其类图如图 6-1 所示。该程序的 Java代码附后。图6-1 类图

【Java 代码】 //颜色类 class MyColor { private int red ,green, blue; public MyColor( ) { red = o; green = 0; blue = 0; } public MyColor(int red ,int green ,int blue) { this.red = red; this.green = green; this.blue = blue; } //其他方法略 public String toString( ) { return "Red: " + red + "\tGreen: " + green + "\tBlue " + blue; } } //调色板类 class Palette { public int number; / /颜色数 private (1)palette; //颜色表 public Palette( ) { number = 256; palette = new MyColor[number); } public Palette(MyColor[] palette ,int number) { (2)= number; (3)= palette; } //其他方法略 public String toString( ) { String str = ""; for (int i = 0; i < number; i++) { str +=i+ " : " + palette[i] + "\n"; } return str; } //绘图类 class Drawing { public (4) int COLORNUMBER = 16; public static void main(String[] args) { Palette palette; int red ,green ,blue; MyColor[] color = new MyColor[COLORNUMBER]; for (int i = 0; i < COLORNUMBER; i++) { red = (int) (Math.random( ) * 256); green = (int) (Math.random( ) * 256); blue = (int) (Math.random( ) * 256); color [i] = (5) (red ,green ,blue); } palette = new Palette(color ,COLORNUMBER); System.out.println(palette); } }


正确答案:(1) MyColor[]
(2) this.number
(3) this.palette
(4) static final
(5) new MyColor

第6题:

对于这样的一个枚举类型:

enum Color:byte

{

Red,

Green,

Blue,

Orange

}


正确答案:
答:string[] ss=Enum.GetNames(typeof(Color));
     byte[] bb=Enum.GetValues(typeof(Color));

第7题:

阅读下列说明和 C++代码,填补代码中的空缺,将解答填入答题纸的对应栏内。 【说明】 设计 RGB 方式表示颜色的调色板,进行绘图,其类图如图 5-1 所示。该程序的 C++代码附后。图5-1 类图

【C++代码】 include <iostream> include <stdlib.h> include <ctime> using namespace std; class MyColor{ private: int red; int green; int blue; public: MyColor() {red = 0; green = 0; blue = 0; } ~MyColor() { } MyColor(int red ,int green ,int blue) { this->red = red; this->green = green; this->blue = blue;} //其他方法略 void print() { cout<<"Red: " << red << "\tGreen: " << green << "\tBlue " << blue << endl; } }; class Palette ( private: int number; MyColor** palette; public: Palette() { number = 256; palette = (MyColor*)malloc (sizeof(MyColor ) *number); } ~Palette () { for (int i = 0; i < number; i++) { delete palette[i]; } (1) ; } Palette(MyColor** pale ,int number) { (2) = number; palette = (MyColor**)malloc(sizeof(MyColor*)*number) ; memcpy(palette ,pale ,sizeof(pale)*number); } //其他方法略 void print () { for (int i = 0; i < number; i++) { cout << i << " : " ; palette[i]->print(); } } }; class Drawing{ public: (3) int COLORNUMBER = 16; public: ~Drawing () { } void draw() ( Palette* palette; int red ,green ,blue; MyColor* color[COLORNUMBER); srand((unsigned)time(O)); for (int i = 0; i < COLORNUMBER; i++) red=rand ()% 256; green = rand() % 256; blue = rand ()% 256; color [i) = (4) (red ,green ,blue); } palette = new Palette(color ,COLORNUMBER); palette->print(); for (int i = 0; i < COLORNUMBER; i++) delete color[i]; } }; int main () { Drawing * d = (5) ; d->draw(); delete d; }


正确答案:(1) free(palette)
(2) this->number
(3) static const
(4) new MyColor
(5) new Drawing()

第8题:

packagesun.scjp;publicenumColor{RED,GREEN,BLUE}packagesun.beta;//insertcodeherepublicclassBeta{Colorg=GREEN;publicstaticvoidmain(String[]argv){System.out.println(GREEN);}}TheclassBetaandtheenumColorareindifferentpackages.Whichtwocodefragments,insertedindividuallyatline2oftheBetadeclaration,willallowthiscodetocompile?()

A.importsun.scjp.Color.*;

B.importstaticsun.scjp.Color.*;

C.importsun.scjp.Color;importstaticsun.scjp.Color.*;

D.importsun.scjp.*;importstaticsun.scjp.Color.*;

E.importsun.scjp.Color;importstaticsun.scjp.Color.GREEN;


参考答案:C, E

第9题:

public class test(  public static void main(string[]args){  string foo = args [1];  string foo = args [2];  string foo = args [3];  }  )  And command line invocation: Java Test red green blue   What is the result?()  

  • A、 Baz has the value of “”
  • B、 Baz has the value of null
  • C、 Baz has the value of “red”
  • D、 Baz has the value of “blue”
  • E、 Bax has the value of “green”
  • F、 The program throws an exception.

正确答案:F

第10题:

Which declarations will allow a class to be started as a standalone program?()  

  • A、public void main(String args[])
  • B、public void static main(String args[])
  • C、public static main(String[] argv)
  • D、final public static void main(String [] array)
  • E、public static void main(String args[])

正确答案:D,E

更多相关问题