【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc

上传人:proposalcash356 文档编号:1338383 上传时间:2019-10-17 格式:DOC 页数:6 大小:43KB
下载 相关 举报
【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc_第1页
第1页 / 共6页
【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc_第2页
第2页 / 共6页
【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc_第3页
第3页 / 共6页
【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc_第4页
第4页 / 共6页
【计算机类职业资格】计算机二级JAVA-86 (1)及答案解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、计算机二级 JAVA-86 (1)及答案解析(总分:100.00,做题时间:90 分钟)一、简单应用题(总题数:3,分数:100.00)1.在本程序中,窗口里有一个文本框和一个文字标签,用户在文本框中输入任意字符串,后面的文字标签都能实时显示出来,如图所示。 (分数:30.00)_2.本程序的功能是打印出指定类的所有属性,包括类的构造函数、类的属性变量和类的方法。例如运行程序时指定方法为“java.util.Date”,则打印出类 Date 的所有信息。 import java.lang.reflect.*; public class exam_22 public static void ma

2、in(String args) throws ClassNotFoundException if(args.length1) System.out.println(“请输入类的名称!“); return; _c=Class.forName(args0); print_class(c); public static void print_class (Class c) if(c.isInterface() System.out.print(Modifier.toString(c.getModifiers() + “ “ + typename(c); else if (c.getSuperclas

3、s() != null) System.out.print(Modifier.toString(c.getModifiers() + “ class “ + typename(c) + “ extends “ + typename(c.getSuperclass(); else System.out.print(Modifier.toString(c.getModifiers() + “ class “ + typename(c); Class interfaces=c.getInterfaces(); if (interfaces != null) else System.out.print

4、(“ implements “); for(int i=0; i interfaces.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(interfacesi); System.out.println(“ “); System.out.prlntln(“ / Constructors“); Constructor constructors=c.getDeclaredConstructors(); for(int i=0; i constructors.length; i+) print_method_

5、or_constructor(constructorsi); System.out.println(“ / Fields“); Field fields=c.getDeclaredFields(); for(int i=0; i fields.length; i+) print_field(fieldsi); System.out.println(“ / Methods“); _=c.getDeclaredMethods(); for(int i=0; i methods.length; i+) print_method_or_constructor(methodsi); System.out

6、.println(“); public static String typename(Class t) String brackets=“ “; while(t.isArray() brackets += “; t=t.getComponentType(); String name=t.getName(); int pos=name.lastIndexOf(“.“); if (pos != -1) name=name.substring(pos+1); return name + brackets; public static String modifiers(int m) if (m = 0

7、) return “ “; else return Modifier.toString(m) + “ “; public static void print_field(Field f) System.out.println(“ “ + modifiers(f.getModifiers() + typename(f.getType() + “ “ + f.getName() + “;“); public static void print_method_or_constructor (Member member) Class returntype=null, parameters, excep

8、tions; if (member instanceof Method) Method m=(Method) member; returntype=m.getReturnType(); parameters=m.getParameterTypes(); exceptions=m.getExceptionTypes(); System.out.print(“ “ + modifiers(member.getModifiers() + typename(returntype) +“ “+ member.getName() + “(“); else Constructor c=(Constructo

9、r) member; parameters=c.getParameterTypes(); exceptions=c.getExceptionTypes(); System.out.print(“ “ + modifiers(member.getModifiers() + typename(c.getDeclaringClass() + “(“); for(int i=0; i parameters.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(parametersi); System.out.pri

10、nt (“)“); if (exceptions.length 0) System.out.print(“ throws “); for(int i=0; i exceptions.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(exceptionsi); System.out.println(“;“); (分数:30.00)_3.本程序的功能是用按钮来控制文字的颜色。窗口中有三个按钮:“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,单击任意一个按钮,文

11、字标签中的文本就变成按钮对应的颜色,如图所示。 (分数:40.00)_计算机二级 JAVA-86 (1)答案解析(总分:100.00,做题时间:90 分钟)一、简单应用题(总题数:3,分数:100.00)1.在本程序中,窗口里有一个文本框和一个文字标签,用户在文本框中输入任意字符串,后面的文字标签都能实时显示出来,如图所示。 (分数:30.00)_正确答案:()解析:第 1 处:import javax.swing.event.* 第 2 处:textField.getText()2.本程序的功能是打印出指定类的所有属性,包括类的构造函数、类的属性变量和类的方法。例如运行程序时指定方法为“ja

12、va.util.Date”,则打印出类 Date 的所有信息。 import java.lang.reflect.*; public class exam_22 public static void main(String args) throws ClassNotFoundException if(args.length1) System.out.println(“请输入类的名称!“); return; _c=Class.forName(args0); print_class(c); public static void print_class (Class c) if(c.isInterf

13、ace() System.out.print(Modifier.toString(c.getModifiers() + “ “ + typename(c); else if (c.getSuperclass() != null) System.out.print(Modifier.toString(c.getModifiers() + “ class “ + typename(c) + “ extends “ + typename(c.getSuperclass(); else System.out.print(Modifier.toString(c.getModifiers() + “ cl

14、ass “ + typename(c); Class interfaces=c.getInterfaces(); if (interfaces != null) else System.out.print(“ implements “); for(int i=0; i interfaces.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(interfacesi); System.out.println(“ “); System.out.prlntln(“ / Constructors“); Const

15、ructor constructors=c.getDeclaredConstructors(); for(int i=0; i constructors.length; i+) print_method_or_constructor(constructorsi); System.out.println(“ / Fields“); Field fields=c.getDeclaredFields(); for(int i=0; i fields.length; i+) print_field(fieldsi); System.out.println(“ / Methods“); _=c.getD

16、eclaredMethods(); for(int i=0; i methods.length; i+) print_method_or_constructor(methodsi); System.out.println(“); public static String typename(Class t) String brackets=“ “; while(t.isArray() brackets += “; t=t.getComponentType(); String name=t.getName(); int pos=name.lastIndexOf(“.“); if (pos != -

17、1) name=name.substring(pos+1); return name + brackets; public static String modifiers(int m) if (m = 0) return “ “; else return Modifier.toString(m) + “ “; public static void print_field(Field f) System.out.println(“ “ + modifiers(f.getModifiers() + typename(f.getType() + “ “ + f.getName() + “;“); p

18、ublic static void print_method_or_constructor (Member member) Class returntype=null, parameters, exceptions; if (member instanceof Method) Method m=(Method) member; returntype=m.getReturnType(); parameters=m.getParameterTypes(); exceptions=m.getExceptionTypes(); System.out.print(“ “ + modifiers(memb

19、er.getModifiers() + typename(returntype) +“ “+ member.getName() + “(“); else Constructor c=(Constructor) member; parameters=c.getParameterTypes(); exceptions=c.getExceptionTypes(); System.out.print(“ “ + modifiers(member.getModifiers() + typename(c.getDeclaringClass() + “(“); for(int i=0; i paramete

20、rs.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(parametersi); System.out.print (“)“); if (exceptions.length 0) System.out.print(“ throws “); for(int i=0; i exceptions.length; i+) if (i 0) System.out.print(“, “); System.out.print(typename(exceptionsi); System.out.println(“;“); (分数:30.00)_正确答案:()解析:第 1 处:Class 第 2 处:Method methods(或 Method methods)3.本程序的功能是用按钮来控制文字的颜色。窗口中有三个按钮:“Yellow”、“Blue”和“Red”,它们分别对应文字标签中文本的颜色为黄色、蓝色和红色,单击任意一个按钮,文字标签中的文本就变成按钮对应的颜色,如图所示。 (分数:40.00)_正确答案:()解析:第 1 处:jl.setForeground(color) 第 2 处:jl.repaint()

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试资料 > 职业资格

copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
备案/许可证编号:苏ICP备17064731号-1