一,指出下面程序的运行结果
class A {
static {
System.out.print("1");
}
public A() {
System.out.print("2");
}
}
class B extends A{
static {
System.out.print("a");
}
public B() {
System.out.print("b");
}
}
public class Hello {
public static void main(String[] args) {
A ab = new B();
ab = new B();
}
}
答案:1a2b2b
二,下面的方法,当输入为2的时候返回值是多少?()
public static int getValue(int i) {
int result = 0;
switch (i) {
case 1: result = result + i;
case 2: result = result + i * 2;
case 3: result = result + i * 3;
}
return result;
}
A,0 B,2 C,4 D,10
答案:D
三,指出下列程序运行的结果 ()
public class Example {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' };
public static void main(String args[]) {
Example ex = new Example();
ex.change(ex.str, ex.ch);
System.out.print(ex.str + " and ");
System.out.print(ex.ch);
}
public void change(String str, char ch[]) {
str = "test ok";
ch[0] = 'g';
}
}
A、 good and abc
B、 good and gbc
C、 test ok and abc
D、 test ok and gbc
答案:B
四,选项中哪一行代码可以替换题目中//add code here而不产生编译错误?()
public abstract class MyClass {
public int constInt = 5;
//add code here
public void method() {
}
}
A 、public abstract void method(int a);
B、 constInt = constInt + 5;
C 、public int method();
D 、public abstract void anotherMethod() {}
答案:A
五,SQL题目,表结构如下
表:T_STUDENT(SNO,SNAME,SAGE,SSEX),学生信息表(编号,姓名,年龄,性别)
表:T_COURSE(CNO,CNAME) ,课程表(编号,名称)
表:T_SCORE(SNO,CNO,GRADE) ,成绩表(学生编号,课程编号,分数)
题目
1,查询课程名称为"JAVA程序设计",且分数低于60的学生姓名和分数
**答案:
select st.sname, sc.grade
from t_score sc
join t_student st
on sc.sno = st.sno
join t_course co
on sc.cno = co.cno
where sc.grade < 60
and co.cname = 'JAVA程序设计';**
2,查询各科成绩最高和最低的分:以如下形式显示:课程编号,课程名,最高分,最低分
答案:
select sc.cno, co.cname, max(grade), min(grade)
from t_score sc
join t_course co
on sc.cno = co.cno
group by sc.cno, co.cname
3,统计各科成绩,以如下形式显示:该分数段人数,课程编号,课程名称。
分数段划分如下:[100-90]优,[90-80]良,[80-70]中,[70-60]一般,[<60]不及格
答案:
select sc.cno,co.cname,
sum(case
when sc.grade > 90 then
1
end) 优,
sum(case
when sc.grade > 80 and sc.grade < 90 then
1
end) 良,
sum(case
when sc.grade > 70 and sc.grade < 80 then
1
end) 中,
sum(case
when sc.grade > 60 and sc.grade < 70 then
1
end) 一般,
sum(case
when sc.grade < 60 then
1
end) 不及格
from t_score sc join t_course co on sc.cno = co.cno
group by sc.cno,co.cname