選擇題
1:
what will be printed when you execute the following code?
class x
{
y b = new y();
x()
{
system.out.print("x");
}
}
class y
{
y()
{
system.out.print("y");
}
}
public class z extends x
{
y y = new y();
z()
{
system.out.print("z");
}
public static void main(string[] args)
{
new z();
}
}
choices:
what will be printed when you execute the following code?
class x
{
y b = new y();
x()
{
system.out.print("x");
}
}
class y
{
y()
{
system.out.print("y");
}
}
public class z extends x
{
y y = new y();
z()
{
system.out.print("z");
}
public static void main(string[] args)
{
new z();
}
}
choices:
a.z
b.yz
c.xyz
d.yxyz
2:
1. public class x {
2. public object m () {
3. object o = new float (3.14f);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. oa[0] = null;
8.return o;
9. }
10.}
when is the float object created in line 3, eligible for garbage collection?
1. public class x {
2. public object m () {
3. object o = new float (3.14f);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. oa[0] = null;
8.return o;
9. }
10.}
when is the float object created in line 3, eligible for garbage collection?
a.just after line 5
b.just after line 6
c.just after line 7
d.just after line 8(that is, as the method returns)
3:which statement about the garbage collection mechanism are true?
a.garbage collection require additional programe code in cases where multiple threads are running.
b.the programmer can indicate that a reference through a local variable is no longer of interest.
c.the programmer has a mechanism that explicity and immediately frees the memory used by java objects.
d.the garbage collection mechanism can free the memory used by java object at explection time.
4:which declares for native method in a java class corrected?
a.public native void method(){}
b.public native void method();
c.public native method();
d.public void native method();
5:which are not java keywords?
a.true
b.const
c.super
d.void
6:which statement about listener is true?
a.most component allow multiple listeners to be added.
b.if multiple listener be add to a single component, the event only affected one listener.
c.component don?t allow multiple listeners to be add.
d.none
7:
public class outerclass {
private double d1 = 1.0;
//insert code here
}
you need to insert an inner class declaration at line 3. which two inner class declarations are
valid?
public class outerclass {
private double d1 = 1.0;
//insert code here
}
you need to insert an inner class declaration at line 3. which two inner class declarations are
valid?
a.class innerone{ public static double methoda() {return d1;} }
b.public class innerone{ static double methoda() {return d1;} }
c.private class innerone{ double methoda() {return d1;} }
d.static class innerone{ protected double methoda() {return d1;} }
8:public class parent {
int change() {…}
}
class child extends parent {
}
which methods can be added into class child?
a.public int change(){}
b.abstract int chang(){}
c.private int change(){}
d.none
9:
what will happen when you attempt to compile and run the following code?
class base
{
int i = 99;
public void amethod()
{
system.out.println("base.amethod()");
}
base()
{
amethod();
}
}
public class derived extends base
{
int i = -1;
public static void main(string argv[])
{
base b = new derived();
system.out.println(b.i);
b.amethod();
}
public void amethod()
{
system.out.println("derived.amethod()");
}
}
choices:
what will happen when you attempt to compile and run the following code?
class base
{
int i = 99;
public void amethod()
{
system.out.println("base.amethod()");
}
base()
{
amethod();
}
}
public class derived extends base
{
int i = -1;
public static void main(string argv[])
{
base b = new derived();
system.out.println(b.i);
b.amethod();
}
public void amethod()
{
system.out.println("derived.amethod()");
}
}
choices:
a.derived.amethod() -1 derived.amethod()
b.derived.amethod() 99
c.compile time error
d.derived.amethod()
10:
what is the result when you compile and run the following code?
public class throwsdemo
{
static void throwmethod()
{
system.out.println("inside throwmethod.");
throw new illegalaccessexception("demo");
}
public static void main(string args[])
{
try
{
throwmethod();
}
catch (illegalaccessexception e)
{
system.out.println("caught " + e);
}
}
}
choices:
what is the result when you compile and run the following code?
public class throwsdemo
{
static void throwmethod()
{
system.out.println("inside throwmethod.");
throw new illegalaccessexception("demo");
}
public static void main(string args[])
{
try
{
throwmethod();
}
catch (illegalaccessexception e)
{
system.out.println("caught " + e);
}
}
}
choices:
a.compilation error
b.runtime error
c.compile successfully, nothing is printed.
d.inside throwmethod. followed by caught:java.lang.illegalaccessexcption: demo
11:what is written to the standard output given the following statement:system.out.println(4|7);
select the right answer:
a.4
b.5
c.6
d.7
12:
give the code fragment:
if(x>4){
system.out.println(“test 1”);}
else if (x>9){
system.out.println(“test 2”);}
else {
system.out.println(“test 3”);}
which range of value x would produce of output “test 2”?
give the code fragment:
if(x>4){
system.out.println(“test 1”);}
else if (x>9){
system.out.println(“test 2”);}
else {
system.out.println(“test 3”);}
which range of value x would produce of output “test 2”?
a.x<4
b.x>4
c.x>9
d.none
13:
the following code is entire contents of a file called example.java,causes precisely one error during compilation:
class subclass extends baseclass{
}
class baseclass(){
string str;
public baseclass(){
system.out.println(“ok”);}
public baseclass(string s){
str=s;}}
public class example{
public void method(){
subclass s=new subclass(“hello”);
baseclass b=new baseclass(“world”);
}
}
which line would be cause the error?
the following code is entire contents of a file called example.java,causes precisely one error during compilation:
class subclass extends baseclass{
}
class baseclass(){
string str;
public baseclass(){
system.out.println(“ok”);}
public baseclass(string s){
str=s;}}
public class example{
public void method(){
subclass s=new subclass(“hello”);
baseclass b=new baseclass(“world”);
}
}
which line would be cause the error?
a.9
b.10
c.11
d.12
14:
public class x{
public object m(){
object o = new float(3.14f);//line 3
object [] oa = new object[1];//line 4
oa[0] = o;//line 5
o=null;//line 6
return oa[0];//line 7
}
}
when is the float object, created in line 3,eligible for garbage collection?
public class x{
public object m(){
object o = new float(3.14f);//line 3
object [] oa = new object[1];//line 4
oa[0] = o;//line 5
o=null;//line 6
return oa[0];//line 7
}
}
when is the float object, created in line 3,eligible for garbage collection?
a.just after line 5.
b.just after line 6
c.just after line 7(that is,as the method returns)
d.never in this method
15:a class design requires that a member variable should be accessible only by same package, which modifer word should be used?
a.protected
b.public
c.no modifer
d.private
16:
給出下面的代碼片斷。。。下面的哪些陳述爲錯誤的?
1) public void create() {
2) vector myvect;
3) myvect = new vector();
4) }
給出下面的代碼片斷。。。下面的哪些陳述爲錯誤的.?
1) public void create() {
2) vector myvect;
3) myvect = new vector();
4) }
a.第二行的聲明不會爲變量myvect分配內存空間。
b.第二行語句創建一個vector類對象。
c.第三行語句創建一個vector類對象。
d.第三行語句爲一個vector類對象分配內存空間
簡答題
17:硬盤上儲存有一個密碼錶,文字檔案格式,檔案名爲“code.txt”,內容如下:
abcdefghijklmnopqrstuvwxyz
ushecginpaywdqmlxbozrtfvjk
試編寫程序實現一個簡單的加密程序,循環讀取用戶輸入,按此密碼錶將字元進行替換,
並直接打印輸出;例如“baidu”將被替換成“super”。
18:循環的有序數組(比如1,2,3,4,5,-3,-2,-1這種數列)裏查找一個數。
19:請問你在什麼情況下會在你的java代碼中使用可序列化?爲什麼放到httpsession中的對象必須要是可序列化的?
21:介紹java中的collection framework(包括如何寫自己的數據結構)?
22:談談final, finally, finalize的區別。
23:spring的容器的實際代表者是哪個類(接口),該類常見的子類有那些?
24:簡單介紹一下ioc的實現原理。(寫出代碼最好)
25:簡述 jdbc 的基本功能。