package sun.scjp;  public enum Color { RED, GREEN, BLUE }  p

题目
多选题
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题:

● 以下CSS 选择符定义中, (61) 属于类选择符。

(61)

A. P {color:red; font-size:12pt }

B. p.blue{color:blue}

C. #Red{color:red;}

D. P EM { background: yellow }


正确答案:B

试题(61)分析
  本题考查CSS的基础知识。
  CSS(Cascading Style. Sheets,层叠样式表,简称为样式表)是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言。
  在CSS基本语法结构中,样式表的结构为:
  选择符{属性1:值1;属性2:值2;...}
  其中,选择符有如下几种形式:
  (1)HTML标记。任何HTML标记都可以是一个CSS的选择符,如P{color:red;font-size:12pt}。
  (2)类选择符。一个选择符能有不同的CLASS(类),因而允许同一元素有不同的样式。
  格式如下:
  标记名:类名{属性1:值1;属性2:值2;...}
  (3)ID选择符。ID选择符个别地定义每个元素的成分。这种选择符应该尽量少用,因为它具有一定的局限。一个ID选择符的指定要有指示符“#”在名字前面。
  (4)关联选择符。关联选择符是用空格隔开的两个或更多的单一选择符组成的字符串。这些选择符可以指定一般属性,而且因为层叠顺序的规则,它们的优先权比单一的选择符大。

第2题:

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

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

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

C.struct color {int red , int green : int blue : )cl;

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


正确答案:B
解析:本题考核的知识点是结构体类型定义。结构体类型的定义格式为:strcut结构体名{成虽说明列表};结构体变量的定义有3种形式:第一种,定义结构体型的同时定义结构体变量,如:strcut结构体名{成员说明列表}变量;选项C属于这种情况,故选项C正确:第二种,先定义一个结构体类型,然后使用该类型来定义结构体变量,如:strcutstudent{成员说明列表}:student变量;选项A属于这种情况,故选项A正确;第三种,定义一个无名称的结构体类型的同时定义结构体变量,如:strcutstudent{成员说明列表}变量;选项D属于这种情况,故选项D正确.所以,4个选项中选项B符合题意。

第3题:

● 以下CSS 选择符定义中, (61) 属于类选择符。

A. P {color:red; font-size:12pt } B. p.blue{color:blue}

C. #Red{color:red;} D. P EM { background: yellow }


正确答案:B

第4题:

以下选项中不能正确把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)不符合结构体类型定义的语法规则。

第5题:

publicclassBall{publicenumColor{RED,GREEN,BLUE};publicvoidfoo(){//insertcodehere{System.out.println(c);}}}Whichcodeinsertedatline14causesthefoomethodtoprintRED,GREEN,andBLUE?()

A.for(Colorc:Color.values())

B.for(Colorc=RED;c<=BLUE;c++)

C.for(Colorc;c.hasNext();c.next())

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

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


参考答案:A

第6题:

( 18 )下列枚举类型的定义中,包含枚举值 3 的是

A ) enum test {RED, YELLOW, BLUE, BLACK};

B ) enum test {RED, YELLOW=4, BLUE, BLACK};

C ) enum test {RED=-1, YELLOW,BLUE, BLACK};

D ) enum test {RED, YELLOW=6, BLUE, BLACK};


正确答案:A

第7题:

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


正确答案:(1)WindowEvent e (2)new JPanel() (3)new JLabel (4)colorPanel (5)new simple()
(1)WindowEvent e (2)new JPanel() (3)new JLabel (4)colorPanel (5)new simple() 解析:本题考查在Java中实现对面板颜色的控制。
题目要求三原色红、绿、蓝,通过任意拖动其对应的一个滑动条来改变,而面板的颜色也会发生对应的变化。这需要我们了解Java中对滑动条和颜色进行定义的类。下面我们来分析程序。
第(1)空在类simple的构造函数中,这个类是继承JFrame这个框架类的,这个构造函数的作用是创建一个框架。很明显此空是函数windowClosing()的参数,而这个函数的作用我们不难看出是关闭框架用的,其参数是WindowEvent e,因此,此空答案就为 WindowEvent e。
第(2)空是给JPanel类型的变量p赋一个值,JPanel类型是控制板类型,在程序上面申请了一个容器,此空应该是在容器中创建一个控制板,而Java中一般用关键字new来创建对象,因此,此空答案为new JPanel()。
第(3)空是给变量greenLabel赋一个初值,从程序中我们不难看出greenLabel是一个标签类型的变量,且其中存放的是绿色的值。结合程序中上下红和蓝的处理我们也不难推断出此空的答案为new JLabel。
第(4)空是容器对象contentPane的add()函数的参数,这个函数的作用是往其对象中增加内容,其第一个参数是要添加的对象,第二个参数是添加的位置,从程序中不难看出应该添加对象colorPanel,这是界面中下面的板块。因此,此空答案为colorPanel。
第(5)空是给JFrame类型的变量f赋一个值,而JFrame是框架类simple的父类,那么变量f应该是一个框架对象,关键字new一般用来创建一个新的对象,因此,此空答案为new simple()。

第8题:

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

Aolor:=‘green‘;

Bwriteln(green);

Cwriteln(color);

Da:=color=red;


正确答案:D

第9题:

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

第10题:

下列枚举类型的定义中,包含枚举值3的是

A.enum test{RED,YELLOW,BLUE,BLACK};

B.enum test{RED,YELLOW=4,BLUE,BLACK};

C.enum test{RED=-1,YELLOW,BLUE,BLACK};

D.erium test{RED,YELLOW=6,BLUE,BLACK};


正确答案:A
解析:在枚举类型定义中,如果没有进行显式设置,则隐式设置整数值。将枚举声明中的第一个枚举值设置为O。后续所有成员的值如果没有进行显式设置,便确定为前一个成员的值加1。所以只能选择答案A)。选项B)中对应的枚举值是0,4,5,6;选项c)中对应的枚举值是-1,0,1,2;选项D)中对应的枚举值是0,6,7,8。

更多相关问题