没有合适的资源?快使用搜索试试~ 我知道了~
Java全国自考历年考试(参考答案)2.doc
资源推荐
资源详情
资源评论
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/89490266/bg1.jpg)
JAVA 知识
Java 全国自考历年考试(参考答
案)
![](https://csdnimg.cn/release/download_crawler_static/89490266/bg2.jpg)
JAVA 知识
————————————————————————————————
———————————————————————————————— 日期:
![](https://csdnimg.cn/release/download_crawler_static/89490266/bg3.jpg)
JAVA 知识
全国 2021 年 1 月 Java 语言程序设计试题
一、单项选择题(本大题共 10 小题,每题 1 分,共 10 分)
1.以下字符组合不能作为 Java 整型常量的是( )
A.078 B.0x3ACB C.5000 D.0x3ABC
2.以下程序代码的输出结果是( )
int x = 10;
while (x > 7) { System.out.print("*"); x--;}
A.** B.*** C.* D.****
3.设类 U 声明,及对象 u 和 v 的定义如下:
class U{
int x, int y;
U(int a, int b){x= a; y = b;}
void copy(U a){ x = a.x; y = a.y;}
}
U u = new U(1, 2), v = new U(2, 3);
在以下供选择的代码中,可能引起系统回收内存的是( )
A.u.x=v.y;u.y=v.x; B.u=v; C.u.copy(v); D.v.copy(u);
4.设有以下代码:
String s l="123";
String s2="123";
String s3=new String("123");
那么表达式 s1==s2 和 s1==s3 的值分别是( )
A.true,true B.false,false C.true,false D.false,true
5.以下关于 AWT 与 Swing 之间关系的表达,正确的选项是( )
A.Swing 是 AWT 的提高和扩展
B.在写 GUI 程序时,AWT 和 Swing 不能同时使用
C.AWT 和 Swing 在不同的平台上都有相同的表示
D.AWT 中的类是从 Swing 继承的
6.在以下 Swing 组件中,能为它指定布局管理器的是( )
A.JScrollBar 对象 B.JMenuBar 对象 C.JComboBox 对象 D.JDialog 对象
7.一般的绘图程序要定义一个 JPanel 子类。在 JPanel 子类中还要重定义一个方法,在这个方
法中调用绘图方法,绘制各种图形。要重定义的方法是( )
A.paint() B.paintComponent() C.repaint() D.update()
8.用 Runnable 接口实现多线程的主要工作是( )
A.声明实现 Runnable 接口的类,在类内实现 run()方法,让线程调用 start()方法。
B.声明实现 Runnable 接口的类,在类内实现 run()方法,在类内声明线程对象,在 init()方法
中创立新线程,启动新线程。
C.声明实现 Runnable 接口的类,在类内实现 run()方法,在类内声明线程对象,在 init()方法
或 start()方法中创立新线程,在 start()方法中启动新线程。
D.声明实现 Runnable 接口的类,在类内实现 run()方法,在 init()方法中创立新线程,在 start()
方法中启动新线程。
9.程序如果要按行输入输出文件的字符流,最合理的方法是采用( )
A.BufferedReader 类和 BufferedWriter 类 B.InputStream 类和 OutputStream 类
C.FileReader 类和 FileWriter 类 D.File_Reader 类和 File_Writer 类
![](https://csdnimg.cn/release/download_crawler_static/89490266/bg4.jpg)
JAVA 知识
10.在编写访问数据库的 Java 程序中,要用到 DriverManager 类。该类的作用是( )
A.存储查询结果 B.处理与数据库的连接
C.在指定的连接中处理 SQL 语句 D.处理驱动程序的加载和建立数据库连接
二、填空题(本大题共 10 小题,每题 2 分,共 20 分)
11.Java 程序的字节码文件的扩展名是__.class__。
12.构造一个 Java 表达式:y/x>5,并且 x!=0。这个表达式是___y/x>5&&x!=0______。
13.在类声明之前用____final_____修饰,声明类是不能被再继承的类,即它不能再有子类。
14.设有字符串定义:
String s="ABCDABCD";
那么表达式 s.indexOf("B")的值是____1_____。
15.在实现接口 ActionListener 的方法 actionPerformed()中,常用的有两个获得事件源的方法,
它们是 getActionCommand()和_____getSource()____。
16.使用单项选择按钮的方法是将一些单项选择按钮用_____ButtonGroup____对象分组,使同
一组内的单项选择按钮只允许一个被选中。
17.在 Java 语言中,用类 Font 对象设置字型。如果要设置的字型是:细明体、正常风格
(Font.PLAIN) , 12 磅 字 号 , 构 造 这 样 要 求 的 Font 对 象 fnA 的 代 码 是 __Font f=new
Font(“Font.PLAIN〞,细明体,12);_______。
18.线程从阻塞状态恢复到就绪状态,有三种途径:自动恢复、用 resume()方法恢复和用
__notify()或 notifyAll()___方法恢复。
19. 为 普 通 的 8 位 字 节 流 文 件 读 和 写 操 作 提 供 支 持 的 类 是 _FileInputStream 和
FileOutputStream_。
20.Connection 类是 java.sql 包中用于处理与数据库连接的类。Connection 对象是用来表示__
数据库连接___的对象,Java 程序对数据库的操作都在这种对象上进行。
三、简答题(本大题共 6 小题,每题 3 分,共 18 分)
21.请写出表示 year 年是闰年的 Java 表达式。闰年的条件是:每 4 年一个闰年,但每 100 年
少一个闰年,每 400 年又增加一个闰年。
(year%4==0 && year%100!=0 || (year%400==0)
22.请写出在类的方法的定义之前,加上修饰字 public、private 的区别。
public 修饰的方法是共有的,其他类的方法都可以访问;而 private 修饰的方法是私有的,
其他类都不能访问。
23.请写出将文本区 text 放置于滚动面板 jsp,并将滚动面板 jsp 添加到 JFrame 窗口 myFrame
的 Java 语句。
JTextArea text=new JTextArea();
JScrollPane jsp=new JScrollPane(text); myFrame.getContentPane().add(jsp);
24.要用 Graphics2D 类的方法画一个图形,首先要把参数对象 g 强制转换成 Graphics2D 对象;
然后,用图形类提供的静态方法 Double()创立一个图形对象;最后,以图形对象为参数调用
Graphics2D 对象的 draw()方法绘制这个图形。请写出用这样的方法绘制一条线段的程序段,
线段的两个端点分别是(10.0,10.0)和(30.0,30.0)。
Graphics2D g2d=(Graphics2D)g;
Line2D line=new Line2D.Double(10.0,10.0,30.0,30.0);
g2d.draw(line);
25.请写出字符流数据与字节流数据的区别。
字符流数据每次读写的单位是一个字符,即 16 位;字节流数据每次读写的单位是一个字节,
即 8 位。
![](https://csdnimg.cn/release/download_crawler_static/89490266/bg5.jpg)
JAVA 知识
26.请写出 URLConnection 类在编写 Java 网络应用程序中的作用。
URLConnection 的作用是建立网络资源的连接,用于发送和接收信息。
四、程序填空题(本大题共 5 小题,每题 4 分,共 20 分)
27.方法 int sigmaDigit(int n)的功能是求出十进制整数 n 的各位数字之和。例如,n=1234,该
方法的返回值是 10。
static int sigmaDigit( int n )
{ int sum = 0, d;
while( n > 0 ){
d=n% 10;
sum=sum+d ;
n/= 10;
}
return sum ;
}
28.以下小应用程序能响应鼠标按动的事件,当鼠标在正文区的某个位置被点击时,就在该
位置显示一个记号“×〞,程序限制最多保存最新 20 个位置。
import java.applet.*; import java.awt.*;
import javax.swing.*; import java.awt.event.*;
class MyPanel extends JPanel {
public void print(Graphics g, int x, int y)(
g.setColor(Color.red);
g.drawLine(x-5, y-5, x+5, y+5);
g.drawLine(x+5, y-5, x-5, y+5);
}
}
class MyWindow extends JFrame implements MouseListener{
final int MaxMarks = 20;
int currentMarks = 0, markCount = 0;
Point marks[] = new Point[MaxMarks];
MyPanel panel;
MyWindow(){
this.setLocation(100, 100); this.setSize(300, 300);
Container con = this.getContentPane();
panel = new MyPanel(); con.add(panel);
panel.addMouseListener(this);
this.setVisible(true);
}
public void paint(Graphics g){
int i;
g.clearRect(0,0, this.getWidth(), this.getHeight());
for(i =0;i < markCount; i++) {
panel.print (g, marks[i].x, marks[i].y);
}
剩余121页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/b2eea90f35534baf8acca9eeb2368e99_zhangao_fengg.jpg!1)
zhangao_fengg
- 粉丝: 24
- 资源: 5万+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)