中软Java笔试题目
4. HasStatic hs1=new HasStatic( );
5. hs1.x++;
6. HasStatic hs2=new HasStatic( );
7. hs2.x++;
8. hs1=new HasStatic( );
9. hs1.x++;
10. HasStatic.x- -;
11. System.out.println(“x=”+x);
12. }
13.}
A、5行不能通过编译,因为引用了私有静态变量
B、10行不能通过编译,因为x是私有静态变量
C、程序通过编译,输出结果为:x=103
D、程序通过编译,输出结果为:x=102
15、以下选项中循环结构合法的是( ):
A、while (int i<7){
i++;
System.out.println(“i is “+i);
}
B、int j=3;
while(j){
System.out.println(“ j is “+j);
}
C、int j=0;
for(int k=0; j + k !=10; j++,k++){
System.out.println(“ j is “+ j + “k is”+ k);
}
D、int j=0;
do{
System.out.println( “j is “+j++);
if (j = = 3) {continue loop;}
}while (j<10);
三、简答题(40分)
1. 写出下列程序的运行结果
public class Cat
{
void mi( ) throws NullPointerException
{
System.out.println( “Cat mi mi .. “ );
}
}
public class SmallCat extends Cat
{int i=8;
void mi( ) throws Exception
{
System.out.println( “SmallCat mi mi .. “ );
}
public static void main( String[] a ) throws Exception
{
Cat cat = new SmallCat();
cat.mi();
}
}
写出下列程序的运行结果
interface Playable {
void play();
}
interface Bounceable {
void play();
}
interface Rollable extends Playable, Bounceable {
Ball ball = new Ball(“PingPang”);
}
class Ball implements Rollable {
private String name;
public String getName() {
return name;
}
public Ball(String name) {
this.name = name;
}
public void play() {
ball = new Ball(“Football”);
System.out.println(ball.getName());
}
}
写出下列程序的运行结果
class Value{
public int i = 15;
}
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.first();
}
public void first(){
int i = 5;
Value v = new Value();
v.i = 25;
second(v, i);
System.out.println(v.i);
}
public void second(Value v, int i){
i = 0;
v.i = 20;
Value val = new Value();
v = val;
System.out.println(v.i + ” ” + i);
}
}
写出下列程序的运行结果
class MyThread extends Thread{
public void run(){
System.out.println(“MyThread: run()”);
}
public void start(){
System.out.println(“MyThread: start()”);
}
}
class MyRunnable implements Runnable{
public void run(){
System.out.println(“MyRunnable: run()”);
}
public void start(){
System.out.println(“MyRunnable: start()”);
}
}
public class MyTest {
public static void main(String args[]){
MyThread myThread = new MyThread();
MyRunnable myRunnable = new MyRunnable();
Thread thread = new Thread(myRunnable);
myThread.start();
thread.start();
}
}
2. 1~100共一百个自然数,放入一个99个元素的数组a[99],要求用java语言编写出一个尽量简单的程序,找出没有被放入数组的这个数。
3. 简要叙述一下什么是数据库连接池,有何作用。
4. 简要描述Struts,spring,hibernate?
Java笔试题目(二)
一、选择题
1、下列表达式正确的()?
A.byte b = 128;
B.boolean flag = null;
C.float f = 0.9239;
D.long a = 2147483648L;
2、下列正确的说法有():
A.声明抽象方法,大括号可有可无
B.声明抽象方法不可写出大括号