中国开发网: 论坛: 程序员情感CBD: 贴子 114683
Water-E
JAVA这个也比较基础
1) 以下哪几个在编译时不会出现错误或警告信息

a) float f = 1.3;
b) int i = 10;
c) boolean b = null;
d) byte b = 128;
e) char c = “c”;

2) 编译执行以下代码时,会出现什么信息
public class MyClass {
public static void main(String arguments[]){
amethod(arguments);
}

public void amethod(String[] arguments){
System.out.println(arguments);
System.out.println(arguments[1]);
}
}

a) error Can't make static reference to void amethod.
b) error method main not correct
c) error array must include parameter
d) amethod must be declared with String

3) byte 类型的范围是

a) -128 to 127
b) (-2 power 8 )-1 to 2 power 8
c) -255 to 256
d) 依赖于虚拟机的不同而不同

4) char 类型的范围是

a) -128 to 127
b) (-2 power 8 )-1 to 2 power 8
c) -255 to 256
d) 依赖于虚拟机的不同而不同

5) 以下哪一些是java的关键字

a) if
b) then
c) goto
d) while
e) case
f) break

6) 以下哪些变量命名是符合规则的

a) 2variable
b) variable2
c) _whatavariable
d) 变量1
e) $anothervar
f) #myvar

7) 以下代码编译执行时会输出什么
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

8) 以下代码编译执行时会输出什么
public class Q {
public static void main(String argv[]){
int anar[]= new int[]{1,2,3};
System.out.println(anar[1]);
}
}

a) 1
b) Error anar is referenced before it is initialized
c) 2
d) Error size of array must be defined

9) 以下代码编译执行时会输出什么
public class Q {
public static void main(String argv[]){
int anar[]= new int[5];
System.out.println(anar[0]);
}
}

a) Error: anar is referenced before it is initialized
b) null
c) 0
d) 5

10) 以下代码编译执行时会输出什么
abstract class MineBase {
abstract void amethod();
static int i;
}

public class Mine extends MineBase{
public static void main(String argv[]){
int[] ar = new int[5];
for(i = 0;i < ar.length;i++)
System.out.println(ar[i]);
}
}

a) a sequence of 5 0's will be printed
b) Error: ar is used before it is initialized
c) Error Mine must be declared abstract
d) IndexOutOfBoundes Error i

11) 以下代码编译执行时会输出什么
int i = 1;
switch (i) {
case 0:
System.out.println(“zero”);
break;
case 1:
System.out.println(“one”);
case 2:
System.out.println(“two”);
default:
System.out.println(“default”);
}

a) one
b) one, default
c) one, two, default
d) default

12) 以下代码编译执行时会输出什么
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”);
}

a) default
b) default, zero
c) error default clause not defined
d) no output displayed

13) 以下代码尝试编译运行时会发生什么?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}

public class CEx{
public static void main(String argv[]){
Base b = new Base();
Sub s = (Sub) b;
}
}

a) Compile and run without error
b) Compile time Exception
c) Runtime Exception

14) 程序阅读,输出内容为
public static void main(String[] args) {
int i = 0;
if (i++ >= 8 || i++ >= 7 || i++ >= 6 || i++ >= 5 || i++ >= 4 || i++ >= 3 ||
i++ >= 2 || i++ >= 1 || i++ >= 0)
System.out.println(i);
}
a) 0
b) 1
c) 2
d) 3
e) 4
f) 5
g) 6
h) 7
i) 8

15) 程序阅读,会产生输出的有哪几行
private static void testStr(String [] ss,int i1, int i2){
if(ss[i1] == ss[i2])
System.out.println("ss[" + i1 + "] == ss[" + i2 + "]");
}
public static void main(String [] args){
String [] ss = new String[5];
ss[0] = "test string";
ss[1] = new String("test string");
ss[2] = "test string";
ss[3] = new String("test string");
ss[4] = ss[0];
testStr(ss,0,1);//第1行
testStr(ss,0,2);//第2行
testStr(ss,0,4);//第3行
testStr(ss,1,3);//第4行
}

a) 第1行
b) 第2行
c) 第3行
d) 第4行

16) 在Java中,以下哪一些不是用作定义一个方法的修饰

a) private
b) friend
c) protected
d) generic
e) static
f) synchronized

17) 程序阅读,输出结果为
public static void main(String [] args){
byte b = (byte)4096;
if(b == 4096)
System.out.println("==");
else
System.out.println("!=");
}

a) ==
b) !=

18) 程序阅读,输出结果为
public class TestInhertiedA {
protected void a(){
System.out.println("A");
}
protected void b() {
a();
}
}

public class TestInhertiedB extends TestInhertiedA {
protected void a() {
System.out.println("B");
}
public static void main(String [] args){
TestInhertiedA a = new TestInhertiedB();
a.b();
}
}

a) A
b) B

19) 补充程序
已知数据库中有数据视图:view_4test(id VARCHAR2(12),SHOW CHAR(2), TEXT VARCHAR2(200), Created VARCHAR2(20))其中id非空、SHOW的取值范围是["Y","N"](Y表示需要显示,N表示不需要显示)、TEXT表示要显示的文本内容、Created表示记录创建的时间。
补充程序实现按照创建时间的先后顺序显示所有需要显示的内容。
public void showTexts(Connection con){
Statement stmt = null;
ResultSet rs = null;
try{
//补充代码位置,输出使用 System.out.println(text);

}finally{
DBUtil.releaseResultSet(rs);
DBUtil.releaseStatement(stmt);
}
}
20) 补充程序
已知数据库中数据表tbl_4test(rid VARCHAR2(12),index integer,value VARCHAR2(200))
补充程序实现向数据库中插入数据。要求:1)如果rid对应的内容存在需要先进行删除;2)使用事务处理;3)index从0开始;4)使用指定的sql语句。
public void insertData(String rid, int index, String [] values){
Connection con = null;
PreparedStatement psDel = null;
PreparedStatement psIns = null;
String strDel = "DELETE FROM tbl_4test WHERE rid = ?";
String strIns = "INSERT INTO tbl_4test (rid, index, value) VALUES (?,?,?)";
try{
con = DBUtil.getConnection();
//补充代码位置
}finally{
DBUtil.releaseStatement(psIns);
DBUtil.releaseStatement(psDel);
DBUtil.releaseConnection(con);
}
}
21) 补充程序
接上题,已知数据库中有存储过程pro_4test(rid VARCHAR2, index integer, value VARCHAR2),功能为向数据表tbl_4test中插入数据。
补充程序实现向数据库中插入数据。要求:1)如果rid对应的内容存在需要先进行删除;2)使用事务处理;3)index从0开始;4)插入数据使用存储过程。
public void insertData(String rid, int index, String [] values){
Connection con = null;
PreparedStatement psDel = null;
CallableStatement csIns = null;
String strDel = "DELETE FROM tbl_4test WHERE rid = ?";
try{
con = DBUtil.getConnection();
//补充代码位置
}finally{
DBUtil.releaseStatement(csIns);
DBUtil.releaseStatement(psDel);
DBUtil.releaseConnection(con);
}
}
22) 补充程序
在指定位置补充程序实现以树形结构输出数据。
public class TreeTypeTest{
Vector v = new Vector();//Vector中保存的是所有的TreeNode

private class TreeNode{
int id;//当前节点的唯一表示(>=0)
int fid;//当前节点的父节点ID(>=0),如果为根节点则为-1
String text;//要显示的内容
}

String showvalues(int fid,int level){
//补充代码位置,要求level + 1层的数据显示比level层数据显示缩进2个空格
}

void insertValue(){
//添加数据信息,不需要补充
}

public static void main(String [] args){
TreeTypeTest ttt = new TreeTypeTest();
ttt.insertValue();
System.out.println(ttt.showvalues(-1,0));
}
}
嘿嘿

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录