Java模拟考试一、名词解释
1、java的三个基本特征,并加以解释
2、从用户的角度看,Java源程序中的类分为哪两种
3 解释this,super的使用场合
4、在java语言说明类的成员有哪四种级别的访问控制
5、说明重载与覆盖的区别
6、在java语言中写出定义类的最一般形式
7、类修饰符用于指定类的使用特性和访问权限,通常有哪几种
8、简单说明静态成员变量的特征
二、选择题
1、下面程序段的输出结果是:
int a = 3;
a++);
a);
A.444 B.445 C. 345 D.344
结果:
2、以下哪些是基本数据类型
B. String
C. integer
D. Float
结果:
3、选择以下程序运行结果
" " +4 + 5;
+ 5);
+ 5 +"");
+ "" +5);
A.第3行出现编译错误 B.输出45, 7, 7 和45.
C.输出7, 7, 7 和45. D.输出 45, 7, 45 和45.
结果:
4、选择以下程序运行结果
public class test {
public static void main(String args[]) {
int x=2,y=2,z=2;
if (x-- == 1 && y++ == 1 || z++ == 1)
"x=" + x + ",y=" + y + ",z=" + z);
} }
A. x=1,y=3,z=2 B. x=2,y=3,z=2
C. x=1,y=2,z=2 D. x=1,y=3,z=3
结果:
5、编译和运行以下代码结果为:
public class EqualsTest{
public static void main(String args[]){
byte A=(byte)4096;
if(A==4096) "Equal");
else "Not Equal");
} }
A.在第3行出现转换丢失精度的编译错误. B.输出 "Not Equal".
C.输出“Equal“. D. 无输出结果
结果:
6、现有一个int类型的整数和一个double类型的数进行加法运算,则得到的结果类型为()
A.int类型 B. double类型 C. float类型 D. long类型
7、以下程序的运行结果为()
public class Test{
public static void main(String argv[ ]){
"x="+5); } }
A. 5
B. x=5
C. "x="+5
D. "x="5
8、以下程序的运行结果为()
public class Test{
public static void main(String argv[ ]){
"good"+"morning"); } }
A. goodmorning
B. "good"+"morning"
C. good morning
D. good+morning
9、选择以下程序运行结果()
以下代码的输出结果
public class Test{
int x=3;
public static void main(String argv[]){
int x= 012;
}
}
A.12 B.012 C.10 D.3 10、选择以下程序运行结果()
public class Exa
{
public static void main(String[] args)
{ int var1=10;
int var2=20;
+ " " + var2);
}
}
A. 3021 21 C. 1020 21 20
11、请问,以下代码片段错在何处()
switch(i==10)
{
case 1:
++i;
break;
case 2:
--i;
case 3:
i*=5;
break;
default:
i%=3;
}
A. switch表达式的结果必须是一个整数类型
B.第一个case的选择因子值是一个字符型
C.第二个case的选择因子值是一个字符串型
D.第二个case的选择分支中缺少break语句
三、写出下列程序的运行结果
1、class Variable{
int x=1,y=2,z=3;
void init( int x, int y ){
= x;
=y;
int z=5;
"**** in init ****");
"x = “+x+" y = “+y+" z = "+z);
} }
public class test1 {
public static void main( String[] args) { Variable birth = new Variable();
(10,20);
}
} 结果:
**** in init ****
X = 10 y = 20 z = 5
2、public class SimpleDataType {
public static void main (String args [ ] ) { int i = 3;
byte bi = (byte)i;
short si = 20000;
int li=(int);
float f = 3.14f;
"\t"+si+"\t"+i+"\t"+li+"\t"+f);
boolean b = false;
int i1 = 4;
b = ( i1!= 0 );
"\n"+b);
} }
结果:
3 20000 3 4
true
3、 class A
{void callme(){
"Inside A's callme() method");
}}
class B extends A{
void callme()
{"Inside B's callme() method");
}}
public class Chinese{
public static void main(String [] args)
{B a=new B();
();
}} 结果:
Inside B's callme() method
4、public class test {
public static void main(String a[]) { "\t");
"\t");
"\t");
"\t");
"%="+%;
}
} 结果:
1 1 -1 -1
%=
5、public class A {
protected void test(int x,int y) { "test(int,int):"+x+" "+y); }
protected void test(int x)
{ "test(int):" + x); }
protected void test(String str )
{ "test(String):" + str); }
public static void main (String[] args)
{ A a1 = new A();
("hello");
(5,4); }} }
结果:
test(String):hello
test(int,int):5 4
6、 public class test {
public static void main(String a[]) {
int m=0;
"m++="+m++);
"++m="+(++m));
boolean x;
x=(5>3)&&(4==6);
"x="+x);
m=m%2;
"result="+m+1);
int y=m*m+2*m-1;
"m="+m+",y="+y);
}
}
结果:
m++=0
++m=2
x=false
result=01
m=0,y=-1
6、class Point {
int x,y;
public Point(int x1,int y1) {
x=x1;
y=y1;
}
public static void main(String args[]) { Point p1=new Point(2,3);
Point p2=new Point(3,5);
Point p3=p1;
=18;
p1=p2;
}
}
【运行结果】
18
3
7、public class Test{
int i=1;
public static void main(String[] args){ Test x= new Test();
(3); }
void thisDemo(int i){
= i;
} }
【运行结果】
3
1
3
8、class Father{
private String str=“父类实例变量”; static{父类静态方法”);}
public Father(){父类构造方法”);}
{ }
}
class Son extends Father{
private String str=“子类实例变量”; { }
static{子类静态方法”);}
Son(){子类构造方法”);}
public static void main(String[] arge){ new Son(); }
}
【运行结果】
父类静态方法
子类静态方法
父类实例变量
父类构造方法
子类实例变量
子类构造方法
9、class parent {
int a=3;
void f(){a=a+1;} }
public class Chinese extends parent {
int a=6;
Chinese(){
();
a= a+ -2;
"a="+a);}
public static void main(String[] args) { Chinese cn=new Chinese(); } }
【运行结果】
a=8
10、Class jj { protected int x = 0;
protected void test(int x) {
"test(int):" + x); }
protected void test(String str ) {
"test(String):" + str); }
protected void test(float x) {
"test(float):" + x );
}
protected void test(Object obj) {
"test(Object):" + obj );
}
public static void main (String[] args) { jj a1 = new jj();
("hello"); (5);
;
} }
【运行结果】
test(String): hello
test(int):5
test(float):
四、编写程序
1 求任意一元二次方程的解,若无实数解,求出虚数解。public class jhg
{
public static void main(String[] args)
{
double a,b,c,d,x1,x2;
a = (inputLine());
b = (inputLine());
c = (inputLine());
d = b*b - 4*a*c;
if(d >= 0 )
{
x1 = (-b + (d)) / 2*a ;
x2 = (-b - (d)) / 2*a ;
"x1=" + x1 + " x2=" + x2);
}
else
{
double x,y;
x=(-d)/2*a;
y=(-d)/2*a;
"x1=" + (-b/2*a) + "+" + x + "i");
"x2=" + (-b/2*a) + "-" + y + "i");
}
}
public static String inputLine()
{
String x=null;
BufferedReader br=new BufferedReader(new InputStreamReader);
try {
x=();
} catch(IOException e) { }
return x;
}
}