1.
设
i,j
为类
x
中定义的
double
型变量名
,
下列
x
类的构造函数中不正确的是(
)
A
、
double x(double k )
{
i=k;
return i;
}
B
、
x(double m, double n )
{
i=m;
j=n;
}
C
、
x( )
{
i=0;
j=0;
}
D
、
x(double k )
{
i=k;
}
|
|
2.
package
语句的作用是(
)
A
、
引入一个包
B
、
创建一个包
C
、
既能引入一个包
,
又能创建一个包
D
、
以上皆不对
|
|
3.
在某类的子类中
,
下述方法中必须要实现的方法是(
)
A
、
Public double methoda();
B
、
Static void methoda (double d1);
C
、
Public native double methoda();
D
、
Abstract public void methoda();
|
|
4.
关于下列程序结果正确的是(
)
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
A
、
Error Variable i may not have been initialized
B
、
Null
C
、
1
D
、
0
|
|
5.
以下哪个表达式是不合法的(
)
A
、
String x=”Hello”; int y=9; x+=y;
B
、
String x=”Hello”; int y=9; if(x= =y) { };
C
、
String x=”Hello”; int y=9; x=x+y;
D
、
String x=null; int y=(x!=null)&&(x.length()>0) ? x.length() : 0;
|
|
6.
下列选项中为
java
关键字的是(
)
A
、
default
B
、
Run
C
、
Integer
D
、
implement
|
|
7.
下列哪个方法可以获得一个事件的
ID
号(
)
A
、
int getID()
B
、
String getSource()
C
、
int returnID()
D
、
int eventID()
|
|
8.
给定程序如下
public static void main(String args[]) {
Float f=new Float(4.2f);
Float c;
Double d=new Double(4.2);
float fl=4.2f;
c=f;
}
下列选项中(
)的值为真
.
A
、
f.equals(d)
B
、
c=f
C
、
c==d
D
、
c.equals(f)
|
|
9.
若所用变量都已正确定义
,
以下选项中
,
非法的表达式是(
)。
A
、
a!=4||b==1;
B
、
‘a’ % 3;
C
、
‘a’=1/2;
D
、
‘A’ + 32;
|
|
10.
给定
File f=new File(“aa.txt”);
可以实现向文件尾部读写的是(
)。
A
、
RandomAccessFile f1=new RandomAccessFile(f,”r”);
B
、
RandomAccessFile f1=new RandomAccessFile(f,”a”);
C
、
RandomAccessFile f1=new RandomAccessFile(f,”rw”);
D
、
RandomAccessFile f1=new RandomAccessFile(f,”w”);
|
|
11.
下列说法不正确的是(
)
A
、
java
语言里的线程是没有优先级的
B
、
String
类在
java.lang
包中
C
、
java
语言支持类的序列化
D
、
能序列化的类必须实现
java.io.Serializable
接口
|
|
12.
一个类的成员变量如果要使其可以被同一个包中其它类访问
,
应该选取的修饰符为(
)
A
、
protected
B
、
public
C
、
缺省(没有)
D
、
private
|
|
13.
传递给
public static void main
方法的
String
数组的下标为
0
的元素为(
)
A
、
应用程序的名称
B
、
所传递参数的个数
C
、
所传递参数中的第一个
D
、
以上均不对
|
|
14.
以下由
do-while
语句构成的循环执行的次数是(
)
int k = 0;
do {
++k;
}while ( k < 1 );
A
、
一次也不执行
B
、
执行
1
次
C
、
无限次
D
、
有语法错
,
不能执行
|
|
15.
容器被重新设置大小后,哪种布局管理器的容器中的组件大小不随容器大小的变化而改变?
( )
A
、
CardLayout
B
、
FlowLayout
C
、
BorderLayout
D
、
GridLayout
|
|
16.
如果有类
Person
和其子类
Man
和
Woman,
则如果程序中出现语句
Woman w=new Man()
;下列说法正确的是(
)。
A
、
语句错误
B
、
语句正确
C
、
编译正确但运行错误
D
、
以上均不对
|
|
17.
关于线程的下列说法正确的是(
)
A
、
线程只能通过继承类
Thread
创建
.
B
、
执行
suspend
方法将使线程停止并不能被重新
start.
C
、
线程与进程实际是同一个概念
.
D
、
线程的终止可以通过两种方式实现
:
自然撤销或被停止
.
|
|
18.
使用
FlowLayout
作为布局管理器
,
则向容器中添加对象
component
的正确方法是(
)
A
、
add(component);
B
、
add(“Center”, component);
C
、
add(x, y, component);
D
、
set(component);
|
|
19.
下列哪个不是整数类型的变量(
)
A
、
-10
B
、
045
C
、
0xa1
D
、
67f
|
|
20.
下列哪个选项不会出现编译错误?(
)
A
、
float f = 1.3;
B
、
char c = “a”;
C
、
byte b = 257;
D
、
int i = 10;
|
|
21.
main
方法是
Java Application
程序执行的入口点,关于
main
方法的方法头以下哪项是合法的?(
)
A
、
public static void main
()
B
、
public static void main
(
String[ ] args
)
C
、
public static int main
(
String[ ] arg
)
D
、
public void main
(
String arg[ ]
)
|
|
22.
以下程序
boolean a=false;
boolean b=true;
boolean c=(a&&b)&&(!b);
int result=c==false?1:2;
执行完后
,c
与
result
的值是(
)
A
、
c=false;result=1;
B
、
c=true;result=2;
C
、
c=true;result=1;
D
、
c=false;result=2;
|
|
23.
给定以下程序段
insert code public class foo {
public static void main (String[] args) throws Exception {
printWriter out = new PrintWriter (new java.io.outputStreamWriter (System.out), true) ;
out.printIn(“Hello”);
}
}
要使程序能正确运行
,
在
insert code
处必须添加(
)语句
A
、
import java.io.PrintWriter;
B
、
include java.io.PrintWriter;
C
、
import java.io.OutputStreamWriter;
D
、
include java.io.OutputStreamWriter;
|
|
24.
下列哪个类或接口是类
FilterOutputStream
的构造方法的输入参数(
)
A
、
InputStream
B
、
OutputStream
C
、
File
D
、
RandomAccessFile
|
|
25.
在一个应用程序中有如下定义
:int a[]={1,2,3,4,5,6,7,8,9,10};
为了打印输出数组
a
的最后一个元素
,
下面正确的代码是(
)
A
、
System.out.println(a[10]);
B
、
System.out.println(a[9]);
C
、
System.out.println(a[a.length]);
D
、
System.out.println(a[8]);
|
|
26.
通过下列(
)
I/O
类可以实现对文件类
File
的添加
,
更新操作。
A
、
RandomAccessFile
B
、
Outputstream
C
、
DataOutputstream
D
、
InputStream
|
|
27.
给定程序
class Base{ public void Base() {
System.out.println(“Base”);
}
}
public class In extends Base{
public static void main(String argv[]) {
In i=new In();
}
}
则下列说法正确的是(
)
A
、
出现编译错误
B
、
编译通过但是无输出信息
C
、
输出
”Base”
D
、
运行时产生异常
|
|
28.
下面哪些赋值语句是错误的?(
)
A
、
float f = 11.1;
B
、
double d = 5.3E12;
C
、
char c =’\r’;
D
、
Boolean b=true;
|
|
29.
Java
语言是(
)。
A
、
面向问题的解释型高级编程语言
B
、
面向机器的低级编程语言
C
、
面向过程的编译型高级编程语言
D
、
面向对象的解释型高级编程语言
|
|
30.
在某个类
A
中存在一个方法
:void GetSort(int x),
以下能作为这个方法的重载的声明的是(
)
A
、
void GetSort(float x)
B
、
int GetSort(int y)
C
、
double GetSort(int y)
D
、
void Get(int x,int y)
|
|
31.
若已定义
byte[ ] x= {11,22,33,-66} ;
其中
0≤k≤3
,则对
x
数组元素错误的引用是
( )
。
A
、
x[5-3]
B
、
x[k]
C
、
x[k+5]
D
、
x[0]
|
|
32.
类
System
下列包(
)中。
A
、
java.util
B
、
java.io
C
、
java.awt
D
、
java.lang
|
|
33.
下列语句中错误的是(
)
A
、
StringBuffer sb=new String(‘a’)
B
、
StringBuffer sb1=new StringBuffer();
C
、
StringBuffer sb2=new StringBuffer(20);
D
、
StringBuffer sb3=new StringBuffer(“sss”);
|
|
34.
下列二维数组定义不正确的是(
)
A
、
int []a[] = new int[10][10];
B
、
int a[10][10] = new int[][];
C
、
int a[][] = new int[10][10];
D
、
int [][]a = new int[10][10];
|
|
35.
在单一文件中
import
、
class
和
package
的正确出现顺序是(
)
A
、
package, import, class
B
、
class, import, package
C
、
import, package, class
D
、
package, class, import
|
|
36.
编译
,
运行下列代码后的结果是(
)
public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println(“The age is ” + age);
}
}
A
、
编译
,
运行后没有输出
B
、
编译
,
运行后输出
:The age is 1
C
、
能通过编译
,
但运行时产生错误
D
、
不能通过编译
|
|
37.
构造函数在(
)时被调用
A
、
类定义时
B
、
使用对象的属性时
C
、
使用对象的方法时
D
、
对象被创建时
|
|
38.
如果要向文件
file.txt
中添加数据
,
应如何构建输出流(
)
A
、
OutputStream out=new FileOutputStream(“file.txt”);
B
、
OutputStream out=new FileOutputStream(“file.txt”, “append”);
C
、
FileOutputStream out=new FileOutputStream(“file.txt”, true);
D
、
FileOutputStream out=new FileOutputStream(new file(“file.txt”));
|
|
39.
下列哪个标识符不是
Java
中的保留字(
)
A
、
if;
B
、
then;
C
、
goto;
D
、
case;
|
|
40.
如果通过命令行
java myprog good morning
运行下列程序
,
结果正确的是(
)。
A
、
myprog
B
、
good
C
、
morning
D
、
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 2 at myprog.main(myprog.java:4)
|
|
41.
如果一个程序段中有多个
catch,
则程序会按下列哪种情况执行(
)
A
、
找到合适的异常类型后继续执行后面的
catch
B
、
找到每个符合条件的
catch
都执行一次
C
、
找到合适的异常类型后就不再执行后边的
catch
D
、
对每个
catch
都执行一次
|
|
42.
设
x,y
均为已定义的类名
,
下列声明对象
x1
的语句中正确的是(
)
A
、
public x x1= new y( );
B
、
x x1=x( );
C
、
x x1=new x( );
D
、
int x x1;
|
|
43.
假定有一个可能引起异常的方法,用什么方式告诉方法的调用者要捕获该异常?(
)
A
、
throw Exception
B
、
throws Exception
C
、
new Exception
D
、
不用特别指定
|
|
44.
既能作为类的修饰符
,
也能作为类成员的修饰符的是(
)
A
、
public
B
、
extends
C
、
float
D
、
static
|
|
45.
假定组件
List
定义为
List l=new List(5,true),
则下列描述正确的是(
)
A
、
该列表的最大容量为
5
B
、
该列表可显示
5
行
,
并且为多选模式
C
、
该列表可显示
5
行
,
并且为单选模式
D
、
以上均不对
|
|
46.
下列语句执行后
,a
的值是(
)
int a=13; a%=a/5;
A
、
3
B
、
13
C
、
169
D
、
1
|
|
47.
下列方法定义中
,
正确的是(
)
A
、
int x( ){ char ch=’a’; return (int)ch; }
B
、
void x( ){ …return true; }
C
、
int x( ){ …return true; }
D
、
int x( int a, b){ return a+b; }
|
|
48.
下面是有关子类继承父类构造函数的描述
,
其中正确的是(
)
A
、
创建子类的对象时
,
先调用子类自己的构造函数
,
然后调用父类的构造函数
.
B
、
子类无条件地继承父类不含参数的构造函数
.
C
、
子类必须通过
super
关键字调用父类的构造函数
D
、
子类无法继承父类的构造函数
.
|
|
49.
下列类头定义中
,
错误的是(
)
A
、
class x{}
B
、
public x extends y{ }
C
、
public class x extends y{}
D
、
class x extends y implements y1 { }
|
|
50.
下列关于事件监听器说法正确的是(
)
A
、
一个组件一次只能设置一个监听器
B
、
时间监听器可以从组件中删除
C
、
只要设置一个事件监听器就可对组件中的多种事件进行响应
D
、
进行事件处理时
,
必须使用
try-catch
结构
|
|
51.
给定下列程序段
: public void method(){ (1) if (someTestFails()){ (2) } (3) }
如果要使该方法抛出一个
IOException
当且仅当
someTestFails()
返回值为真时
,
则下列说法正确的是(
)
A
、
在
(1)
处添加
IOException e;
B
、
在
(2)
处添加
throw e;
C
、
在
(2)
处添加
throw new IOException( );
D
、
在
(3)
处添加
throw new IOException( );
|
|
52.
用于定义类成员的访问控制权的一组关键字是
( )
A
、
class, float, double, public
B
、
float, boolean, int, long
C
、
char, extends, float, double
D
、
public, private, protected
|
|
53.
下列哪种情况无法使当前线程停止执行(
)
A
、
线程执行过程中的异常被抛出发生
B
、
线程执行了
sleep()
方法
.
C
、
产生了一个新线程
D
、
具有更高优先级的线程准备就绪
|
|
54.
paint()
方法使用(
)作为起输入参数。
A
、
Graphics
B
、
Graphics2D
C
、
String
D
、
Color
|
|
55.
下列说法错误的是(
)。
A
、
Java Application
命名必须与公共类名相同
B
、
自定义
Applet
通常是类
Applet
的子类
C
、
Applet
中也可以有
main
()方法
D
、
一个
Java Application
文件中可以定义多个类
|
|
56.
关于事件监听器下述说法正确的是(
)
A
、
一个对象最多可以设置一个监听器
B
、
每个监听器的返回值可以用于激活其它的监听器
C
、
如果一个对象可设置多个监听器
,
则每个监听器执行顺序是固定的
.
D
、
在
AWT
中
,
每个监听器的方法都必须取得一个输入参数
,
该参数是
java.awt.AWTEvent
子类的一个实例
.
|
|
57.
给出下列声明
String s=”Example”,
则下列选项中(
)不是合法的代码
A
、
S[3]=”x”;
B
、
int I=s.length();
C
、
String t=”For”+s;
D
、
String t=s.toLowerCase();
|
|
58.
当某区域被毁坏或需要清除时
,AWT
会自动调用下列哪个方法(
)
A
、
paint()
B
、
repaint()
C
、
update()
D
、
destoy()
|
|
59.
下式中给字符串数组正确赋值的语句是(
)。
A
、
String temp [] = new String {“j”, “a”, “z”};
B
、
String temp [] = { “j ” ” b” “c”};
C
、
String temp = {“a”, “b”, “c”};
D
、
String temp [] = {“a”, “b”, “c”};
|
|
60.
给出下列代码段
:
if(x>4){
System.out.println(“Test 1”);
} else if(x>9){
System.out.println(“Test 2”);
} else {
System.out.println(“Test 3”);
}
哪一个范围的
x
取值可以产生输出信息
:”Test 3”
(
)
A
、
小于
0
B
、
5
到
9
之间
C
、
大于等于
10
D
、
以上均不对
|
|
61.
在编写异常处理的
Java
程序中
,
每个
catch
语句块都应该与
( )
语句块对应
,
使得用该语句块来启动
Java
的异常处理机制
.
A
、
if – else
B
、
switch
C
、
try
D
、
throw
|
|
62.
String s=”Example String”;
下列对
s
的操作中(
)是错误的
A
、
int i=s.length();
B
、
s[3]=”x”;
C
、
String short_s=s.trim();
D
、
String t=”root”+s;
|
|
63.
可以替换一个
Container
对象布局的方法(
)。
A
、
setLayout(aLayoutManager);
B
、
addLayout(aLayoutManager);
C
、
layout(aLayoutManager);
D
、
setLayoutManager(aLayoutManager);
|
|
64.
Java
应用中
main()
方法的参数形式正确的是(
)
A
、
String args
B
、
String ar[]
C
、
Char args[][]
D
、
DStringBuffer arg[]
|
|
65.
以下赋值语句中(
)是错误的
.
A
、
float f=1/3;
B
、
int i=1/3;
C
、
float f=1.01;
D
、
double d=999d;
|
|
66.
下列选项不是类修饰符
protected
特征的是(
)
A
、
可被本类访问
B
、
可被子类访问
C
、
可被同一包中其它类访问
D
、
可被不同包中非子类访问
|
|
67.
下列哪个选项不能使当前线程停止执行?(
)
A
、
一个异常被抛出
B
、
线程执行了
sleep()
调用
C
、
高优先级的线程处于可运行状态
D
、
当前线程产生了一个新线程
|
|
68.
Java
中合法标识符是
( )
。
A
、
3d_game
B
、
%passwd
C
、
userName
D
、
this
|
|
69.
下列标识符不合法的是(
)
A
、
2variable
B
、
variable2
C
、
_whatavariable
D
、
_3_
|
|
70.
类
public class returnIt{
returnType methodA(byte x, double y) {
return x/y * 2;
}
}
中的方法
methodA( )
方法的返回值类型为(
)
A
、
Int
B
、
Byte
C
、
Short
D
、
double
|
|
71.
为了使包
sos
在当前程序中可见
,
可以使用的语句是
( ).
A
、
import sos.*
B
、
package sos.*
C
、
include sos
D
、
sos package
|
|
72.
下面关于
Applet
的说法正确的是(
)
A
、
Applet
也需要
main
方法
B
、
自定义
Applet
可以继承自
java.awt.Applet
C
、
Applet
能访问本地文件
D
、
Applet
程序不需要编译
|
|
73.
编译并运行下列程序的正确结果是(
)
public class EqualsTest{
public static void main(String args[]){
Object A=new Long(7);
Long L=new Long(7);
if(A.equals(L)) System.out.println(“Equal”);
else System.out.println(“Not Equal”);
}
}
A
、
Equal.
B
、
Not Equal
C
、
.
编译错误
D
、
以上均不对
.
|
|
74.
如果一个类对象要永久保存,则必须实现接口(
)。
A
、
Runnable
B
、
Enumeration
C
、
Serializable
D
、
Object
|
|
75.
StringBuffer str=new StringBuffer(25);
String s=”Hello”,
若执行语句
str.append(s)
后
,str.length()
和
str.capacity()
的返回值为(
)
A
、
5,5
B
、
25,5
C
、
5,25
D
、
25,25
|
|
76.
关于下列程序
public class Q {
public static void main(String argv[]){
int anar[]= new int[]{1,2,3};
System.out.println(anar[1]);
}
}
以下结论正确的是(
)
A
、
发生编译错误
B
、
1
C
、
2
D
、
数组长度未指定
|
|
77.
下列语句不正确的是(
)。
A
、
int a[][]=new int[][3];
B
、
int a[][]={
{1,3},{2,3,4},{1,2}};
C
、
String s[][]=new String[2][];
D
、
String s[][]={
{“can”,”I”},{“help”,”you”}};
|
|
78.
下列对常量
MAX
定义正确的是(
)
A
、
public int MAX =100;
B
、
static int MAX =100;
C
、
final public int MAX =100;
D
、
public final static int MAX =100;
|
|
79.
下列
InputStream
构造方法正确的是(
)
A
、
InputStream in=new FileReader(“file.txt”);
B
、
InputStream in=new FileInputStream(“file.txt”);
C
、
InputStream in=new InputStreamFileReader (“file.txt”, “read”);
D
、
FileInputStream in=new FileReader(new File(“file.txt”));
|
|
80.
如果定义一个线程类
,
它继承自
Thread,
则我们必须重写其中的(
)方法
A
、
run
B
、
start
C
、
yield
D
、
stop
|
|
1.
java
语言中的逻辑变量可以和整型变量相互强制转换。
正确
错误
|
|
2.
Java
语言支持类的序列化
.
(
)
正确
错误
|
|
3.
字符串
“\’a\'”
的长度是
5.
(
)
正确
错误
|
|
4.
数组的下标从
1
开始计数。
正确
错误
|
|
5.
事件源不能自己监听自己产生的事件
.
正确
错误
|
|
6.
socket
类在
java.lang
中
.
(
)
正确
错误
|
|
7.
Java
中的消息包括消息的接收者
,
接受者所用方法
,
方法所需参数三个部分
.
(
)
正确
错误
|
|
8.
声明为
final
的方法不能被重写。(
)
正确
错误
|
|
9.
静态变量使用前必须初始化。(
)
正确
错误
|
|
10.
Default
子句只能出现在
case
子句后
.
正确
错误
|
|
11.
保留字
this
代表当前对象
.
(
)
正确
错误
|
|
12.
复合语句虽然由多条语句构成,但从功能上可视为一条语句,是一个整体。()
正确
错误
|
|
13.
通过类
FileOutputStream
可以实现对文件的随机处理
.
正确
错误
|
|
14.
Java
中
”+”
运算符除可执行加法运算外也可用于字符串的连接操作。
正确
错误
|
|
15.
for
语句中的循环体不能是空的
.
(
)
正确
错误
|
|
16.
一个接口中只需进行方法的声明,而不提供具体的实现。
正确
错误
|
|
17.
Java
的编译环境和运行环境必须在同一台机器上
.
()
正确
错误
|
|
18.
Java
支持多线程机制。
正确
错误
|
|
19.
进行
AWT
绘制时
,
需要程序员重写
repaint()
方法。
正确
错误
|
|
20.
组件必须放置在一定的容器中才能显示
.
(
)
正确
错误
|
|
21.
创建对象时系统将调用适当的构造方法给对象初始化。
正确
错误
|
|
22.
类
Connection
完成对指定数据库的连接操作
.
(
)
正确
错误
|
|
23.
一个
Java
源程序中允许有多个公共类。
正确
错误
|
|
24.
线程一旦被创建就处于可运行状态
.
(
)
正确
错误
|
|
25.
程序中抛出异常时
(throw …)
,只能抛出自己定义的异常对象。
正确
错误
|
|
26.
数据报通信协议(
UDP
)是一种面向连接的协议
.
正确
错误
|
|
27.
数组成员只能为简单数据类型。
正确
错误
|
|
28.
JDBC API
是一组抽象接口
,
可以通过它实现应用程序与数据库的连接
.
(
)
正确
错误
|
|
29.
对象和类是同一个概念。
正确
错误
|
|
30.
一个布局容器中可以混合使用多种布局策略。
正确
错误
|
|
31.
重载的方法可以通过它们返回值的不同类型来区分。(
)
正确
错误
|
|
32.
抽象类中至少要包含一个抽象方法。
正确
错误
|
|
33.
Java
字节码文件是与具体平台相关的。(
)
正确
错误
|
|
34.
Java
在定义一个类的同时将为该类分配内存空间
.
正确
错误
|
|
35.
main
方法中不能声明抛弃异常。
正确
错误
|
|
36.
不同包中的类的名字可以相同。
正确
错误
|
|
37.
类
RandomAccessFile
提供了对随机文件访问的支持
.
正确
错误
|
|
38.
类的私有属性和私有方法可以被其子类对象访问。
正确
错误
|
|
39.
While
结构与
do..while
结构是完全等价的两种结构
.
(
)
正确
错误
|
|
40.
Java
源程序的文件名必须和公共类的类名相同
.
正确
错误
|
|
1.
public class sumof10
{
public static void main(String args[])
{
int I,sum;
sum=0;
I=1;
do
{
sum+=I; I++;
}
while (I<=10);
System.out.println(“sum=”+sum);
}
}
|
|
2.
import java.io.* ;
public class Reverse{
public static void main(String args[ ]) {
int i , n =5 ;
int a[ ] = new int[5];
for ( i = 0 ; i < n ; i ++ )
try {
BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
a[i] = Integer.parseInt(br.readLine( ));
}
catch ( IOException e ) { } ;
for ( i = n
-
1 ; i >= 0 ; i– )
System.out.print(a[i]+” “);
System.out.println( );
}
}
如果从键盘输入
1 2 3 4 5
则运行结果为
:
|
|
3.
class test
{
public static void main(String args[])
{
int x=4,j=0;
switch(x)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
break;
default: j++;
}
System.out.println(j);
}
}
|
|
4.
public class Leaf{
private int i=0;
Leaf increment( ){
i++;
return this;
}
void print( ){
System.out.println(“i=”+i);
}
public static void main(String args[]){
Leaf x=new Leaf( );
x.increment( ).increment( ).increment( ).print( );
}
}
|
|
5.
import java.io.*;
public class test
{
public static void main(String argv[])
{
test m=new test();
System.out.println(m.amethod());
}
public int amethod()
{
try
{
FileInputStream dis=new FileInputStream(“Hello.txt”);
}
catch (FileNotFoundException fne)
{
System.out.println(“No such file found”);
return -1;
}
catch(IOException ioe)
{
}
finally{ System.out.println(“Doing finally”);
}
return 0;
}
}
如果文件
Hello.txt
并不存在
,
则运行结果是
|
|
6.
public class EqualsTest
{
public static void main(String args[])
{
Long LA=new Long(7);
Long LB=new Long(7);
if(LA==LB) System.out.println(“Equal”);
else System.out.println(“Not Equal”);
}
}
|
|
7.
public class test
{
public static void main(String a[])
{ StringBuffer s=new StringBuffer(“Java”);
String c=new String(“Java”);
Hello(s,c);
System.out.println(s+c);
}
public static void Hello(StringBuffer s, String c)
{
s.append(“C”);
c.replace(”A”,”D”);
}
}
|
|
8.
class Mystery
{
private long val;
public Mystery(long v)
{
val = v;
}
public static void main(String args[])
{
Mystery x = new Mystery(10L);
Mystery y = new Mystery(10L);
Mystery z = y; long a = 10L;
int b = 10;
System.out.println(“the value1=”+(y==z));
System.out.println(“the value2=”+(y==x));
}
}
|
|
9.
import java.io.*;
import java.net.*;
public class Test
{
public static void main(String args[]) throws Exception
{
URL url=new URL(“http://www.163.com:80/news.html”);
System.out.println(“protocol=”+url.getProtocol());
System.out.println(“host=”+url.getHost());
System.out.println(“filename=”+url.getFile());
System.out.println(“path=”+url.getPath()); } }
|
|
10.
文件
file.txt
的内容为
:
How are you
?
import java.io.*;
public class Test{
public static void main(String args[]) throws IOException{
File inputfile=new File(“file.txt”);
FileReader in=new FileReader(inputfile);
int c;
while ((c=in.read())!= -1) { if(c==’’) {
System.out.println();
continue;
}
System.out.print ((char)c);
}
in.close();
}
}
|
|
11.
class Test
{
public static void add3(Integer i)
{
int val=i.intValue();
val+=3; i=new Integer(val);
}
public static void main(String args[])
{
Integer i=new Integer(0);
add3(i);
System.out.println(i.intValue());
}
}
|
|
12.
public class test
{
static StringBuffer sb1=new StringBuffer(“Hello”);
static StringBuffer sb2=new StringBuffer(“Hello”);
public static void main(String args[])
{
aMethod(sb1,sb2);
System.out.println(“sb1 is “+sb1);
System.out.println(“sb2 is “+sb2);
}
public static void aMethod(StringBuffer sb1,StringBuffer sb2)
{
sb2.append(” there”);
sb1=sb2;
}
}
|
|
13.
public class test
{
public static void main(String argv[])
{
boolean b1 = true;
if((b1 ==true) || place(true))
{
System.out.println(“Hello Crowle”);
}
}
public static boolean place(boolean location)
{
if(location==true)
{
System.out.println(“Borcetshire”);
}
System.out.println(“Powick”);
return true;
}
}
|
|
14.
public class demo
{
public static void main(String args[])
{
int bookno=0;
while (bookno<=100)
{
bookno+=10;
if (bookno==40) break;
System.out.println(“the bookno is”+bookno);
}
System.out.println(“This is the end”);
}
}
|
|
15.
class Base
{
int x=3;
public Base() {} public void show()
{
System.out.println(” The value is ” +x);
}
}
class Derived extends Base
{
int x=2;
public Derived() {} public void show()
{
System.out.println(” The value is ” +x);
}
}
public class test
{
public static void main(String args[])
{
Base b = new Derived();
b.show();
System.out.println(“The value is “+b.x);
}
}
|
|
16.
class Base extends Object
{
String objType;
public Base()
{
objType=”I am a Base type”;
System.out.println(objType);
}
}
public class Test extends Base{ public Test()
{
objType=”I am a Derived type”;
System.out.println(objType);
}
public static void main(String args[])
{
Test D=new Test();
}
}
|
|
17.
class A
{
public String toString()
{
return “4”;
}
}
class B extends A
{
public String toString()
{
return super.toString()+”3″;
}
}
public class test
{
public static void main(String args[])
{
B b=new B();
System.out.println(b.toString());
}
}
|
|
18.
public class test{
static int arr[] ={1,2,3,4,5};
public static void main(String args[])
{
System.out.println(arr[]);
}
}
|
|
19.
import java.awt.Graphics; import java.applet.Applet;
public class ttt extends Applet
{
public void paint( Graphics g )
{
int count, xPos = 25;
for ( count = 1; count <= 10; count++ )
{
if ( count == 8 ) break;
g.drawString( ” ” + count, xPos, 25 );
xPos += 10;
}
}
}
问题
:
程序的输出结果是什么?
|
|
20.
public class Test
{
public static void main(String args[])
{
Test d=new Test(); d.divide(4,0);
}
public void divide(int a, int b) {
try
{
int c = a / b;
}
catch (Exception e)
{
System.out.print(“Exception “);
}
finally
{
System.out.println(“Finally”);
}
}
}
|
|
21.
public class SwitchTest
{
public static void main (String []args)
{
System.out.println(“value =” +switchIt(4));
}
public static int switchIt(int x)
{
int j = 1;
switch (x)
{
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default:j++;
}
return j + x;
}
}
|
|
22.
public class test
{
public static void main(String args[])
{
int i=9;
switch (i)
{
default: System.out.println(“default”);
case 0: System.out.println(“zero”);
break;
case 1: System.out.println(“one”);
case 2: System.out.println(“two”);
}
}
}
|
|
23.
interface Foo
{
int k=0;
}
public class test implements Foo
{
public static void main(String args[])
{
int i;
test t =new test();
i=t.k;
i=test.k;
i=Foo.k;
System.out.println(i);
}
}
|
|
24.
public class Calc
{
public static void main (String args [])
{
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, –j)
{
System.out.println(” i = ” + i + ” : j = ” + j);
total += (i + j);
}
System.out.println(“Total ” + total);
}
}
|
|
25.
public class test
{
public static void main(String[] args)
{
StringBuffer a=new StringBuffer(“A”);
StringBuffer b=new StringBuffer(“B”);
operate(a,b);
System.out.println(a+”,”+b);
}
public static void operate(StringBuffer x, StringBuffer y)
{
x.append(y);
y=x;
}
}
|
|
26.
public class test
{
public static void main(String ar[])
{
int j=10;
method(j);
amethod(j);
System.out.println(j);
}
public static void method(int j) { j++; } public static void amethod(int j) { j++; }
}
|
|
27.
public class Test
{
public static void main(String[] args)
{
String foo=args[0];
String bar=args[1];
String baz=args[2];
System.out.println(baz);
}
}
如果执行语句
java Test Red Green Blue
后结果为
|
|
28.
public class Test
{
public static void main(String args[])
{
int x = 2; switch (x)
{ case 1: System.out.println(1);
case 2: case 3: System.out.println(3);
case 4: System.out.println(4);
}
}
}
|
|
29.
class Myexception extends Exception
{
Myexception ()
{
super();
}
Myexception(String msg)
{
super(msg);
}
}
public class Test
{
public static void main(String args[])
{
try
{
throw new Myexception(“
自定义异常
”);
}
catch(Myexception e)
{
System.out.println(e.getMessage());
}
}
}
|
|
30.
class Mystery
{
String s=”original”;
public static void main(String[] args)
{
Mystery m=new Mystery();
m.go();
}
void Mystery()
{
s=”constructor”;
}
void go()
{
System.out.println(s);
}
}
|
|
31.
class Sum
{
int n;
float f()
{
float sum=0;
for(int i=1;i<=n;i++) sum=sum+i;
return sum;
}
}
class Average extends Sum
{
int n;
float f()
{
float c;
super.n=n;
c=super.f();
return c/n;
}
float g()
{
float c;
c=super.f();
return c/2;
}
}
public class Cala
{
public static void main(String args[]) {Average aver=new Average();
aver.n=10;
float result_1=aver.f();
float result_2=aver.g();
System.out.println(“result_1=”+result_1);
System.out.println(“result_2=”+result_2);
}
}
|
|
32.
public class test
{
String s1 = “Initialized at definition”;
String s2;
public test(String s2i)
{
s2 = s2i;
}
public static void main(String args[])
{
test si =new test(“Initialized at construction”);
System.out.println(“si.s1 = ” + si.s1);
System.out.println(“si.s2 = ” + si.s2);
}
}
|
|
33.
public class student
{
String name;
int age;
student()
{
this(“default”,20);
}
student(String a1,int a2)
{
name=a1;
age=a2;
}
public static void main(String args[])
{
student s1=new student();
System.out.println(“name=”+s1.name+”age=”+s1.age);
}
}
|
|
34.
public class test{
public static void main(String args[]){
String s = null;
s.toString();
try { s.toString(); }
catch(Exception e){
System.out.println(“Caught exception ” + e);
}
}
}
|
|
35.
public class test
{
public static void main(String args[])
{
String name[] = {“Killer”,”Miller”};
String name0 = “Killer”;
String name1 = “Miller”;
swap(name0,name1);
System.out.println(name0+”,” +name1);
swap(name);
System.out.println(name[0]+”,” +name[1]);
}
public static void swap(String name[])
{
String temp;
temp=name[0];
name[0]=name[1];
name[1]=temp;
}
public static void swap(String name0,String name1)
{
String temp;
temp=name0;
name0=name1;
name1=temp;
}
}
|
|
1.
什么是对象?如何创建一个对象?
|
|
2.
阅读题下面的程序段
,
回答以下问题
.
if ( x < 5 ) System.out.print(” one “);
else {
if ( y < 5 ) System.out.print(” two “);
else System.out.println(” three “);
}
问题
: 1)
若执行前
x=6, y=8,
该程序段输出是什么
? 2)
若执行前
x=1, y=8,
该程序段输出是什么
?
|
|
3.
说明
while
与
do…while
语句的差异
|
|
4.
方法的覆盖与方法的重载有何不同?
|
|
5.
什么是接口和抽象类
,
它们之间的区别是什么?
|
|
6.
消息的基本构成?
|
|
7.
实例变量和类变量的区别是什么?
|
|
8.
类
System
和
Runtime
分别具有什么作用?
|
|
9.
简述线程与进程的区别。
|
|
10.
String
类与
StringBuffer
类的主要区别是什么?
|
|
11.
线程与进程相比
,
它们的区别是什么?
|
|
12.
什么是
Applet,
如何运行一个
Applet
?
|
|
13.
说明在数据类型转换中
,
什么是隐式类型转换?什么是显示类型转换?
|
|
14.
Applet
中方法
init(),start(),stop()
和
destroy()
的作用?
|
|
15.
使用
socket
进行通讯的基本步骤是什么?
|
|
16.
数据报通信和流式通信的区别是什么?
|
|
17.
说明修饰符
private,public,protected,
缺省的作用范围差异
.
|
|
18.
指出运算符
“
==
”
和方法
equals()
在判断题对象是否相等上的区别?
|
|
19.
如何构造一个线程(两种方法)?
|
|
20.
简述
Java
的异常处理机制?
|
|
21.
简述
Java
程序的执行过程。
|
|
22.
什么是串行化
,
如何进行串行化?
|
|
23.
谈
final, finally, finalize
的区别
.
|
|
24.
一个
URL
有哪几部分组成?
|
|
25.
说明
Java
程序为什么具有可移植性?
|
|
1.
将下列程序改为功能相同但不用
break
的语句形式
.
public class test {
public static void main(String[] args) {
int i,sum;
for(i=1,sum=0; ; i++,sum+=i) if(i>10)break;
System.out.println(“sum=”+sum);
}
}
|
|
2.
给定一个字符串数组
String f[] = {“ab”, “bc”, “cd”, “de”, “ef”};
编程实现从该数组中查找用户指定字符串位置的功能
,
用户指定的字符串由命令行参数输入。
|
|
3.
用
if
嵌套编写求解下述函数的程序
,
给定
x
输出
y
值
. x (0≤x<10) y= x2+1 (10≤x<20) x3+x+1 (20≤x<30 )
|
|
4.
将一个正整数分解质因数。例如:输入
90
,打印出
90=2*3*3*5
。
|
|
5.
编写一个程序,接受用户从键盘输入的
10
个整数,并输出这
10
个整数的最大值和最小值。
|
|
6.
编程
Java
程序
,
实现文本文件
c:\test.txt
的读入并显示功能
.
|
|
7.
编写一个
java
程序将字符串
”Mary was a ”
改为
”Mary had a book.”
|
|
8.
编写程序求所有指定浮点数的平均值
,
要求所有浮点数均通过命令行参数传入(如
java test 11.1 22.2 33.3 44.4
)。
|
|
9.
设计一
Applet,
计算数组
a[] = { 1, 3, 5, 7, 9, 10 }
中各元素的和。
|
|
10.
编写程序使用类
StringBuffer
的
replace
方法将字符串
”Mary was a ”
改为
”Mary had a book.”
|
|
11.
编程求出个位数为
6,
且能被
3
整除的
5
位整数共有多少个?
|
|
12.
编写一个程序,获取
10
个
1~20
的随机数,要求随机数不能重复。
|
|
13.
编写程序删除指定文件
,
要求文件名通过
main
方法的参数传入
.
|
|
14.
编写一个应用程序
,
完成文件的拷贝功能
,
文件名从命令行得到
.
|
|
15.
编程计算
1/1+1/2+1/3+…+1/100
的值
|
|
16.
设计一个
Applet,
在该
Applet
中实现计算学生成绩的功能
:
如果成绩大于
90,
输出优
,
如果成绩大于
70
小于
90,
输出良
,
如果成绩大于
60
小于
70,
输出及格
,
否则输出不及格
.
|
|
17.
编程将键盘输入的数据拷贝当前路径下
test.txt
中,如果遇到
quit
就结束程序。
|
|
18.
编写程序利用
String
中的已有函数将字符串
abcABC123
中的大写转换为小写
,
小写转换为大写
.
|
|
19.
编写程序将任意三个变量
a,b,c
中的值进行交换
,
使得变量
a
的值最小
,b
其次
,c
的值最大
.
|
|
20.
通过键盘传入一个数
,
判断题该数是不是素数(不能被
1
和自身整除的数)
.
|
|
BY:Vip_Hc
无偿分享
E-mail:xysds@protonmail.com
分享保留出处
.
禁止用于任何盈利行为
,
崇拜大神吧。啊哈哈哈哈哈哈哈哈哈哈哈。