单选题public class Ball {  public enum Color { RED, GREEN, BLUE };  public void foo() {  // insert code here  { System.out.println(c); }  }  }  Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?()Afor( Color c : Color.values(

题目
单选题
public class Ball {  public enum Color { RED, GREEN, BLUE };  public void foo() {  // insert code here  { System.out.println(c); }  }  }  Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?()
A

 for( Color c : Color.values())

B

 for( Color c = RED; c <= BLUE; c++)

C

 for( Color c; c.hasNext() ; c.next())

D

 for( Color c = Color[0]; c <= Color[2]; c++)

E

 for( Color c = Color.RED; c <= Color.BLUE; c++)


相似考题

2.阅读以下说明和Java代码,将应填入(n)处的语句写在对应栏内。【说明】本程序通过移动滑动条修改颜色RGB值,从而控制颜色。程序中有一个面板、3个标签和3个滑动条,标签和滑动条一一对应,分别对应三原色红、绿、蓝,任意拖动其中的一个滑动条,所对应的颜色值就会发生变化,面板的颜色也会发生对应的变化,如下图所示,滑动条值的范围是0~255。【Java代码】import java.awt.*;import java.awt.event.*;import javax.swing.*;public class simple extends JFrame. implements AdjustmentListener{public simple(){setTitle("simple");setSize(300, 200);addWindowListener(new WindowAdapter(){public void windowClosing((1)){System.exit(0);}});Container contentPane=getContentPane();JPanel p=(2);p.setLayout(new GridLayout(3, 2));p.add(redLabel=new JLabel("Red 0"));p.add(red=new JScrollBar(Adjustable. HORIZONTAL, 0, 0, 0, 255));red.setBlocklncrement(16);red.addAdjustmentListener(this);p.add(greenLabel=(3) ("Green 0"));p.add(green=new JScrollBar(Adjustable.HORIZONTAL 0, 0, 0, 255));green setBIocklncrement(16);green.addAdjustmentListener(this);p.add(blueLabel=new JLabel("Blue 0"));p.add(btue=new JScrollBar(Adjustable. HORIZONTAL, 0, 0, 0, 255));blue,setBIocklncrement(16);blue.addAdjustmentListener(this);contentPane.add(p, "South");colorPanet=new JPanel();colorPanet.setBackground(new Color(0, 0, 0));contentPane.add((4),"Center");} public void adjustmentValueChanged(AdjustmentEvent evt){redLabel.setText("Red"+red.getValue());greenLabel.setText("Green"+green.getValue());blueLabel.setText("Blue"+blue.getValue());coiorPanel.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));colorPanel.repaint();}public static void main(String[] args){JFrame. f=(5);f.show();}private JLabel redLabel;private JLabel greenLabel;private JLabel blueLabel;private JScrollBar red;private JScroilBar green;private JScrollBar blue;private JPanel colorPanel;

参考答案和解析
正确答案: E
解析: 暂无解析
更多“public class Ball {  public enum Color { RED, GREEN, BLUE };”相关问题
  • 第1题:

    阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。

    【说明】

    下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toStrinS方法输出中心点的值。在MovingBsll类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。

    【Java代码】

    //Point.java文件

    public class Point{

    private double xCoordinate;

    private double yCoordinate;

    public Point(){}

    public Point(double x,double y){

    xCoordinate=x;

    yCoordinate=y;

    }

    public String toStrthg(){

    return"("+Double.toString(xCoordinate)+","

    +Double.toString(yCoordinate)+")";

    }

    //other methods

    }

    //Ball.java文件

    public class Ball{

    private (1);//中心点

    private double radius;//半径

    private String color;//颜色

    public Ball(){}

    public Ball(double xValue, double yValue, double r){

    //具有中心点及其半径的构造方法

    center=(2);//调用类Point中的构造方法

    radius=r;

    }

    public Ball(double xValue, double yValue, double r, String c){

    //具有中心点、半径和颜色的构造方法

    (3);//调用3个参数的构造方法

    color=c;

    }

    public String toString(){

    return "A ball with center"+center.toString()

    +",radius "+Double.toString(radius)+",color"+color;

    }

    //other methods

    }

    class MovingBall (4) {

    private double speed;

    public MovingBall(){}

    public MoyingBall(double xValue, double yValue, double r, String c, double s){

    (5);//调用父类Ball中具有4个参数的构造方法

    speed=s;

    }

    public String toString(){

    return super.toString()+",speed"+Double.toString(speed);

    }

    //other methods

    }

    public class test{

    public static void main(String args[]){

    MovingBall mb=new MovingBall(10,20,40,"green",25);

    System.out.println(mb);

    }

    }


    正确答案:(1) Point center (2) new Point(xValueyValue) (3) this(xValueyValuer) (4) extends Ball (5) super(xValueyValuerc)
    (1) Point center (2) new Point(xValue,yValue) (3) this(xValue,yValue,r) (4) extends Ball (5) super(xValue,yValue,r,c) 解析:在类Ball的有参数构造函数中,对成员变量center通过调用Point类的构造方法初始化,而center在类Ball中尚未声明。结合注释可得空(1)是将center变量声明为Point对象引用,故空(1)应填Point。空(2)是调用Point类的构造函数,根据题意,此处应将xValue和yValue作为参数调用类Point的有参数构造函数,故空(2)应填new Point(xValue,yValue)。
    根据注释,空(3)是调用类Ball的有3个参数的构造方法,而其所在方法本身就是类Ball的一个构造方法,因此可用this来调用自身的构造方法,故空(3)应填this(xValue,yValue,r)。
    根据题述“在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值”,可知类MovingBall是类Ball的子类,因此空(4)应填extends Ball。
    根据注释,空(5)是调用父类Ball中具有4个参数的构造方法,通过super关键字实现,故空(5)应填super(xValue,yValue,r,c)。

  • 第2题:

    以下选项中不能正确把c1定义成结构体变量的是

    A.typedef struct { int red; int green;; int blue; }COLOR; COLOR cl;

    B.struct color cl { int red; int green; int blue; };

    C.struet color { int red; int green; int blue; }c1;

    D.struct { int red; int green; int blue; }cl;


    正确答案:B
    解析:结构体类型的定义格式为:
      stract结构体名
      成员说明列表};
      结构体变量的定义有3种形式:第一种,定义结构体类型的同时定义结构体变量,如: street结构体名{成员说明列表}变量;第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strect student{成员说明列表};student变量;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strect student{成员说明列表}变量;。

  • 第3题:

    本题的功能是用按钮来控制文字的颜色。窗口中有三个按钮“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,单击任意一个按钮,文字标签中的文本就变成按钮对应的颜色。 import java.awt.*; import java.awt.event.*; import javflx.swing.*; class ButtonPanel extends JPanel implements ActionL- istener{ public ButtonPanel{ yellowButton=new J Button("Yellow"); blueButton=new JButton("Blue"); redButton=new JButton("Red"); j1=new JLabel("I am from China!"); add(yellowButton); add(blueButton); add(redButton); add(j1); yellowButtofl.addActionListener(this); blueButton.addActionListener(this); redButton.addActionListener(this); } public void actionPerformed(ActionEvent evt){ 0bject source=evt.getSource; Color color=getForeground; if(source= =yellowButton)color=Color. yellow; else if(source= =blueButton)color=Color. blue; else if(source= =redButton)color= Color.red; ; ; } private JButton yellowButton; private JButton blueButton; private JButton redButton; private JLabel jl; } class ButtonFrame. extends JFrame{ public ButtonFrame{ setTitle("exam l6"); setSize(300,200); addWindowListener(new WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(O); } }); Container contentPane=getContentPane; contentPane.add(new ButtonPanel); } } public class java2{ public static void main(String[]args){ JFrame. frame=new ButtonFrame; frame.show; } }


    正确答案:
    第1处:jl.setForeground(color)
    第2处:jl.repaint
    【解析】在构件类的方法中,setForeground为设置构件的前景色,repaint为重新绘制构件。

  • 第4题:

    以下选项中能正确把c1定义成结构体变量的是( )。

    A.typedef struct { int red; int red; int green; int blue; }COLOR; COLOR c1;

    B.struct color c1 { int red int red; int green int blue; };

    C.stmctcolor { int red, int green; int blue; }c1;

    D.struct { int red; int green; int blue; }c1;


    正确答案:D
    解析:因为结构体中不能出现同名的成员变量,所以选项A和B都是错误的;又因为结构体中成员的定义应该由分号隔开,所以选项C也是错误的。选项D定义了一个无名结构体,并同时定义该结构体变量c1,是正确的写法。故应该选择D。

  • 第5题:

    阅读下列说明和 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()

  • 第6题:

    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

  • 第7题:

    public class Test {  public static void main( String[] args) {  String foo = args[1];  String bar = args[2];  String baz = args[3];  System.out.println(“baz = “ + baz); }  }   And the command line invocation: java Test red green blue   What is the result?()  

    • A、 baz =
    • B、 baz = null
    • C、 baz = blue
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:E

  • 第8题:

    现有:  1. abstract class Color  {  2.protected abstract  String getRGB();     3.  }     4.  5. public class Blue extends Color  {     6.    //insert code here      7.  }  和四个声明:  public String getRGB()  {  return "blue";  }      String getRGB()  {  return  "blue";  )  private  String getRGB()  {  return  "blue";  }      protected String getRGB()  {  return "blue";  )      分别插入到第6行,有几个可以通过编译?()    

    • A、  0
    • B、  1
    • C、  2
    • D、  3

    正确答案:C

  • 第9题:

    public class test(   public static void main(stringargs){   string foo = args [1];   string foo = args ;   string foo = args ;   }   )   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题:

    单选题
    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
    解析: 暂无解析

  • 第11题:

    多选题
    Which three demonstrate an “is a” relationship?()
    A

    public class X {  }     public class Y extends X { }

    B

    public interface Shape { }     public interface Rectangle extends Shape{ }

    C

    public interface Color { }     public class Shape { private Color color; }

    D

    public interface Species { }     public class Animal { private Species species; }

    E

    public class Person { }    public class Employee {      public Employee(Person person) { }

    F

    interface Component { }     class Container implements Component {   private Component[] children; }


    正确答案: A,F
    解析: 暂无解析

  • 第12题:

    单选题
    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”


    正确答案: B
    解析: 暂无解析

  • 第13题:

    以下选项中不能正确把cl定义成结构体变量的是

    A.typedef struct { int red; int green; int blue; } COLOR; COLOR cl;

    B.struct color cl { int red; int green; int blue; }

    C.struct color { int red; int green; int blue; } cl;

    D.struct { int red; int green; int blue; } cl;


    正确答案:B
    解析:选项A)是把结构体类型改名后定义为变量cl。选项C),D)则是在定义结构体类型时定义变量,而选项B)不符合结构体类型定义的语法规则。

  • 第14题:

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

    enum Color:byte{

    Red,

    Green,

    Blue,

    Orange

    }

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

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

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


    正确答案:
     

  • 第15题:

    下列选项中不能正确定义结构体的是_______。

    A.typedef struct

    B.struct color cl {int red; {int red; int green; int green; int blue; int blue; }COLOR; }; COLOR cl;

    C.struct color

    D.struct {int red; {int red; int green; int green; int blue; int blue; }cl; }cl;


    正确答案:B
    解析:将一个变量定义为标准类型与定义为结构体类型不同之处在于:后者不仅要求指定变量为结构体类型,而且要求指定为某一特定的结构体类型(例如,struct color),不能只指定结构体名。其中可以不出现结构体名,答案D就是缺省结构体名的隋况。而变量名歹婊必须放在成员列表后面,所以B答案不能正确将cl定义为结构件变量。

  • 第16题:

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

    enum Color:byte

    {

    Red,

    Green,

    Blue,

    Orange

    }


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

  • 第17题:

    阅读以下说明和 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

  • 第18题:

    Which three demonstrate an “is a” relationship?() 

    • A、 public class X {  }     public class Y extends X { }
    • B、 public interface Shape { }     public interface Rectangle extends Shape{ }
    • C、 public interface Color { }     public class Shape { private Color color; }
    • D、 public interface Species { }     public class Animal { private Species species; }
    • E、 public class Person { }    public class Employee {      public Employee(Person person) { }
    • F、 interface Component { }     class Container implements Component {   private Component[] children; }

    正确答案:A,B,F

  • 第19题:

    Which the two demonstrate an “is a” relationship?()

    • A、 public interface Person {}  Public class Employee extends Person {}
    • B、 public interface Shape {}  public interface Rectangle extends Shape {}
    • C、 public interface Color {}  public class Shape { private Color color; }
    • D、 public class Species {}  public class Animal { private Species species; }
    • E、 interface Component {} Class Container implements Component {private Component [] children;

    正确答案:B,E

  • 第20题:

    Which two demonstrate an “is a” relationship?()   

    • A、 public interface Person { }  public class Employee extends Person { }
    • B、 public interface Shape { }  public class Employee extends Shape { }
    • C、 public interface Color { }  public class Employee extends Color { }
    • D、 public class Species { }  public class Animal (private Species species;)
    • E、 interface Component { }  Class Container implements Component ( Private Component[ ] children;  )

    正确答案:D,E

  • 第21题:

    You work as a Web Developer at Certkiller.com. You make use of Microsoft ASP.NET 3.5 in orderto create a Web Site.  In a separate code file you create the following class:  public static class _Colors {  public static Color NormalActivityColor = Color.Green;  public static Color WarningActivityColor = Color.Yellow;  public static Color ErrorActivityColor = Color.Red;    public static Color GetRandomColor()  {  Random random = new Random((int)DateTime.Now.Ticks);  int randomArgbValue = random.Next();  Color color = Color.FromArgb(255, Color.FromArgb(randomArgbValue));  return color;  }  }  You need to ensure that the class is consumed by the Web Site. You have to configure the WebSite project.  What should you do?()

    • A、You should add the file to the App_Code folder of the project.
    • B、You should add a Register directive that will reference the file to every page that makes use ofthe class.
    • C、This can be accomplished by referencing the file in the assemblies segment of the Web.configfile.
    • D、This can be accomplished by referencing the file in the httpHandlers segment of the Web.configfile.

    正确答案:A

  • 第22题:

    单选题
    public class test(   public static void main(stringargs){   string foo = args [1];   string foo = args ;   string foo = args ;   }   )   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
    解析: 暂无解析

  • 第23题:

    单选题
    public class Ball {  public enum Color { RED, GREEN, BLUE };  public void foo() {  // insert code here  { System.out.println(c); }  }  }  Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?()
    A

     for( Color c : Color.values())

    B

     for( Color c = RED; c <= BLUE; c++)

    C

     for( Color c; c.hasNext() ; c.next())

    D

     for( Color c = Color[0]; c <= Color[2]; c++)

    E

     for( Color c = Color.RED; c <= Color.BLUE; c++)


    正确答案: E
    解析: 暂无解析

  • 第24题:

    多选题
    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;


    正确答案: A,D
    解析: 暂无解析