选择40题,每题1.5分
题数
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
1题
A. Java用Unicode保存字符及字符串
B. “中文”.getBytes().length一定等于4
C. “中文”.equals(new String(“中文”, “UTF-8”), “UTF-8”)为true
D. “中文”???忘记了
1题
ServerSocket server = new ServerSocket(8080);
DatagramSocket socket = new DatagramSocket(8080);
server.accept();
} catch(Exception e) {
e.printStackTrace();
}
System.out.println(“success”);
long d = c * 3;
switch(d)
{
case 4:
System.out.println(“c=4”);
case 5:
System.out.println(“c=5”);
case 6:
System.out.println(“c=6”);
default:
System.out.println(“c=default”);
}
private String str;
public A(String str) {
this.str = str;
}
public static void main(String[] args) {
A a1 = new A(“Hello”);
A a2 = new A(“Hello”);
A a3 = a1;
String s1 = new String(“Hello”);
String s2 = new String(“Hello”);
System.out.println(a1 == a2);
System.out.println(a1.equals(a2));
System.out.println(a1 == a3);
System.out.println(a1.equals(a3));
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
}
}
private static String staticField = “A”;
private String field = “C”;
{
System.out.println(field);
System.out.println(“D”);
}
static {
System.out.println(staticField);
System.out.println(“B”);
}
public Test(String str) {
System.out.println(str);
}
public static void main(String[] args) {
new Test(“E”);
}
}
System.out.println(a/3);
public void changevalue(int a) {
this.a += 100;
}
public static void main(String[] args) {
int a = 10;
changevalue(a);
changevalue(a);
changevalue(a);
System.out.println(a);
}
}
public int I = 10;
class Sub extends Parent {
public int I = 20;
}
class Sub2 {
int I = 3;
public static void main(String[] args) {
Parent p1 = new Parent();
Parent p2 = new Sub();
Sub2 s2 = new Sub2();
System.out.println(p1.i + p2.i + s2.i);
}
}
}
public void run() {
// 代码略..
}
public static void main(String[] args) {
Thread thread1 = new TestThread();
System.out.println(“thread(a): ” + thread1.isLive());
thread1.start();
System.out.println(“thread(b): ” + thread1.isLive());
thread1.join();
System.out.println(“thread: ” + thread1.isLive());
}
}
public static void method1() throws IOException {
throw new IOException();
}
public static void main(String[] args) throws IOException {
try {
method1();
} catch(IOException e) {
System.out.println(“This is IOException”);
} catch(Exception e1) {
System.out.println(“This is Exception”);
} finally {
System.out.println(“This is finally.”);
}
}
}
1题
1题
1题
1题
1题
A. null instanceOf Object
B. NaN == NaN
C. null === undefined
D. null == undefined
1题
1题
填空10空,每空2分
1)用什么修饰声明类属性?(static)
2)用什么修饰方法可以避免子类覆盖该方法?(final)
3)面向对象程序设计的三个基本原则是?(封装,继承,多态)
4)若int a = 1, b = 3,在if(a>b&&a++<5)之后a的值是?
若int a = 1, b = 3,在if(a>b&a++<5)之后a的值是?
5)代码填空(a),(b),(c)。一段读文件写文件的代码。
编程2题,每题10分
1)
① 你知道几种排序算法?列出二个即可。
② 实现一种排序算法,补完以下方法:
public void sort(int[] data) {
}
private void swap(int[] data, int xIndex, int yIndex) {
}
2)实现一个单链表,结点结构为data link,补完以下方法。
public class link {
private static class Node {
// 补完结构
}
public link() {}
public link(Integer[] data) {
// 补完方法
}
public Node getHeader() {
// 补完方法
}
public void printMax() {
// 补完方法
}
}



