第一篇:JAVA程序員基本測試題目
PART 1: The essential of java 1.Given the following code, what test would you need to put in place of the comment line? //place test here to result in an output of the string Equal
public class EqTest{ public static void main(String argv[]){
EqTest e=new EqTest();
}
EqTest(){
String s=“Java”;
String s2=“java”;
//place test here {
System.out.println(“Equal”);
}else
{
System.out.println(“Not equal”);
}
} }
A)if(s==s2)B)if(s.equals(s2)C)if(s.equalsIgnoreCase(s2))D)if(s.noCaseMatch(s2))
2.Given the following code how could you invoke the Base constructor that will print out the string “base constructor”;
class Base{
Base(int i){ System.out.println(“base constructor”);
}
Base(){
} }
public class Sup extends Base{
public static void main(String argv[]){ Sup s= new Sup();//One
}
Sup()
{ //Two
}
public void derived()
{ //Three
} }
A.On the line After //One put Base(10);B.On the line After //One put super(10);C.On the line After //Two put super(10);D.On the line After //Three put super(10);
3.What is the value of seasons.length for the following array?
String[] seasons = {“winter”, “spring”, “summer”, “fall”, };
A.undefined
B.3
C.4
D.5
4.When you use the new keyword to create an object, where is it created? A.Heap
B.Garbage collector
C.Queue
D.Stack
5.What will happen if you attempt to compile and run the following code?
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
6.An overridden method can be in the same class.A.True
B.False
7.Given the following code
import java.io.*;public class Th{
public static void main(String argv[]){ Th t = new Th();t.amethod();
}
public void amethod(){ try{
ioCall();}catch(IOException ioe){}
} } What code would be most likely for the body of the ioCall method A.public void ioCall(){ DataInputStream din = new DataInputStream(System.in);din.readChar();}
B.public void ioCall()throw IOException{ DataInputStream din = new DataInputStream(System.in);din.readChar();} C.public void ioCall()throws IOException{ DataInputStream din = new DataInputStream(System.in);din.readChar();}
D.public void ioCall throws IOException(){ DataInputStream din = new DataInputStream(System.in);din.readChar();
}
8.How do you force the garbage collector to run? A.Call System.gc()
B.Call Runtime.gc()
C.Either A or B
D.There is nothing you can do
9.When multiple methods exist within the same class with different method signatures, this is known as what? A.Method overloading
B.Overriding methods
C.Message passing
D.A headache
10.What's printed when the following program is executed: class PrintMe {
public void do(int character){
System.out.println(character+character);
}
public static void main(String args[]){
new PrintMe().do('A');
} }
A.AA
B.130(The ASCII value of A is 65)
C.Does not compile
11.What will be printed out if you attempt to compile and run the following code?
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
12.What will be the result of attempting to compile and run the following code?
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
Part 2.The essential of jdbc 1.If you need to use a stored procedure with output parameters, which of the following statement type should be used to call the procedure?
A.Statement
B.PreparedStatement
C.CallableStatement
2.Which of the following will not cause a JDBC driver to be loaded and registered with the DriverManager?
A.Class.forName(driverString);
B.new DriverClass();
C.Include driver name in jdbc.drivers system property
D.None of the above 3.From which object do you ask for DatabaseMetaData?
A.Connection
B.ResultSet
C.DriverManager
D.Driver
4.If one intends to work with a ResultSet, which of these PreparedStatement methods will not work?
A.execute()
B.executeQuery()
C.executeUpdate()
5.Can a ResultSet be reliably returned from a method that creates a Statement and executes a query?
A.Yes
B.No
6.How can I use JDBC to create a database?
A.Include create=true at end of JDBC URL
B.Execute “CREATE DATABASE jGuru” SQL statement
C.Execute “STRSQL” and “CREATE COLLECTION jGuru” SQL statements
D.Database creation is DBMS specific
7.Which character is used to represent an input parameter in a CallableStatement?
A.%
B.*
C.?
D.#
8.Which one of the following will not get the data from the first column of ResultSet rs, returned from executing the following SQL statement: SELECT name, rank, serialNo FROM employee.A.rs.getString(0);
B.rs.getString(“name”);
C.rs.getString(1);
9.Which of the following can you do with a JDBC 2.0 database driver that you cannot with a JDBC 1.x driver?
A.Batch multiple statements, to be sent to the database together
B.Scroll through result sets bi-directionally
C.Work with SQL3 data types directly
D.All of the above
10.Which class contains the transaction control methods setAutoCommit, commit, and rollback?
A.Connection
B.Statement
C.ResultSet
Part 3.The essential of xml
1.There is a way of describing XML data, how?
A.XML uses XSL to describe data
B.XML uses a description node to describe data C.XML uses a DTD to describe the data.D.XML uses a SCHEMA to describe the data.2.What is the correct syntax of the declaration which defines the XML version?
A. B. C.
3.Which one is this a correct XML document? A.
第二篇:Java程序員崗前測試
軟件企業程序員入職參考測試題
班級_________
姓名_________(共61題,對52%即通過,時間61分鐘)1 下列哪些是JAVA語言中合法的標識符:
A
fieldname B
super C
3number D #number E $number 下面那些是JAVA的關鍵字:
A final B Abstract C
Long D
static 下面代碼會輸出什么結果:
public class Test{ public static void main(String[] args){
Test o = new Test();
o.amethod();} public void amethod(){ int oi = 012;System.out.println(oi);} } A B 012 C D 10.0 在編譯和運行下面代碼時會發生什么:
public class Test{ public static void main(String[] args){
int[] i = new int[5];
System.out.println(i[5]);} } A 編譯錯誤 B 運行時錯誤 C 輸出0 D 輸出“null” 下列哪些數組的聲明或初始化是正確的:
A
String srt[];B String str[5] = new String[5];
C String str[] =
new
String[]{“s1”,”s2”,”s3”,”s4”,”s5”};
D String str[] = {“s1”,”s2”,”s3”,”s4”,”s5”};下列代碼會輸出什么:
public class Test{ static int j =20;public static void main(String[] args){
int i =10;
Test p =new Test();p.amethod(i);System.out.println(i);System.out.println(j);}
public void amethod(int x){ x=x*2;j=j*2;} } A
編譯錯誤 B 20 和 40 C 10 和 40 D 10 和 20 編譯和運行以下代碼會發生什么:
public class Test{
public static void main(String[] args){
System.out.println(5 | 7);} }
A 編譯錯誤 B 運行期異常 C 輸出5 D 輸出7 E 輸出2 下列哪個語句是錯誤的:
A
float f = 11.1;
B double d = 5.3E12;C double d = 3.14159;D double d = 3.14D;下面代碼會輸出什么:
int i = 16;int j = 17;
System.out.println(i >> 1);System.out.println(j >> 1);A 8和8 B 7和7 C 8和9 D 7和8 10 以下代碼會輸出什么:
System.out.println(010 | 4);A 14 B 0 C 6 D 12 請看下列代碼:
String s = “hello”;String t = “hello”;
Char c[] = {?h?,?e?,?l?,?l?,?o?};選項中哪些返回true: A s.equals(t);B t.equals(c);C s == t;D t.equals(new String(“hello”));E t == c;請看下列代碼:
class Test{ public static void main(String[] args){
int s = 10;
s >>= 10;
System.out.println(“s=” + s);
} } 選擇正確的答案: A 編譯錯誤 B 運行錯誤 C 0 D 1 請看以下代碼:
public static void main(String[] args){ Float f = new Float(4.2f);Float c;Double d = new Double(4.2);float f1 = 4.2f;c = f;} 下列哪些是正確的: A f.equals(d);B c == f;C c == d;D c.equals(f);下面的代碼哪些是正確的定義了一個抽象類:
A class Test{
abstract void grow1();} B abstract Test{
abstract void grow1();
} C class abstract Test{ abstract void grow1();} D abstract class Test{ abstract void grow1();} E abstract class Test{ abstract void grow1(){ }
} 下面哪些是JAVA中合法的修飾符:
A private B public C protected D protect E
friend 編譯和運行以下代碼時會發生什么:
public class Test{ private int i;public static void main(String[] args){
Test s = new Test();
s.amethod();
}
public static void amethod(){ System.out.println(i);} }
A 輸出0 B 沒有輸出 C 編譯錯誤 D 運行錯誤 試圖編譯和運行以下代碼時會發生什么:
class Test{ protected int i=99;}
public class Ab{ private int i = 1;public static void main(String[] args){ Ab a = new Ab();a.hallow();} abstract void hallow(){ System.out.println(i);} } A 編譯錯誤
B 編譯通過并輸出99 C 編譯通過并輸出1 D 編譯通過但運行時沒有輸出 試圖編譯和在控制臺上輸入java Test hello there運行以下代碼時會發生什么: public class Test{ String[] myArg;public static void main(String[] args){
myArg = args;} public void amethod(){ System.out.println(args[1]);} } A 編譯錯誤
B 編譯通過并輸出hello C 編譯通過并輸出there D 以上都不對 以下代碼有什么錯誤?選出所有正確的答案:
final class Test{ private int a = 1;int b = 2;} class Second extends Test{ public void method(){ System.out.println(a + b);} } A println方法應該傳入String類型的參數
B a是私有的,所以除了Test類以外別的類不能訪問
C Second不能繼承Test D
final不是一個關鍵字下列哪些選項可以放置在×××處:
public class OuterClass{ private String s = “I am outer class member variable”;
class InnerClass{
private String s1 = “I am inner class variable”;
public void innerMethod(){
System.out.println(s);
System.out.println(s1);}
} //inner class
public static void outerMethod(){
//×××
inner.innerMethod();}
}//outerclass
A OuterClass.InnerClass inner = new OuterClass().new InnerClass();
B InnerClass inner = new InnerClass();C new InnerClass();D 以上選項都不對編譯和運行以下代碼會發生什么:
public class Test{ public static void main(String[] args){
Test h = new Test();}
protected Test(){ for(int i=0;i<10;i++){
System.out.println(i);
} } }
A 編譯錯誤:構造方法不能聲明成protected B 運行時錯誤:構造方法不能聲明成protected C 編譯通過并輸出0到10 D 編譯通過并輸出0到9 編譯和運行以下代碼會發生什么:
class Test{ public static void main(String[] args){ try{
byte x = 5;
byte y = x *2;System.out.println(y);}catch(Exception e){ System.out.println(“exception”);}//catch }//main }//class Test A 編譯錯誤
B 輸出exception C 5 D 10 E 15 F 20 G 25 下列哪些語句在編譯時不會有警告或錯誤:
A float f = 1.3;B char c = “a”;C byte b = 257;D boolean b = null;E int i = 10;一個類中帶有一個成員變量,如果不希望這個成員變量被除了自己之外的其他任何類訪問,那么這個變量應該使用哪個修飾符修飾: A private B public C transient D final E abstract 一個整型變量x的二進制值為:1001 1100,如下語句執行之后z的值是: int y = 1 << 7;int z = x & y;A 1000 0001 B 1000 0000 C 0000 0001 D 1001 1101 E 1001 1100 下面程序運行的時候將會產生哪些輸出:
public class Test {
public static void main(String args[]){
double d =-2.9;
int i =(int)d;
i *=(int)Math.ceil(d);
i *=(int)Math.abs(d);
System.out.println(i);
} }
A 12 B 18 C 8 D 12 E 27 請看下面的代碼:
void looper(){
int x = 0;
one:
while(x < 10){
two:
System.out.println(++x);
if(x > 3)
break two;
} }
選擇所有有效的答案:
A 代碼編譯成功 B 代碼編譯錯誤
C 代碼執行后將會打印處數字0 D 將會打印數字1和2 E 將會打印數字3
看下面的代碼,將會打印出什么結果:
int m = 0;
while(m++ < 2)
System.out.println(m);
A 0 B 1 C 2 D 3
E 什么都沒有,而且會產生一個異常錯誤 29 查看如下申明:
char[] c = new char[100];c[50]的內容是什么: A 50 B 49 C 'u0000' D 'u0020' E 在賦值之前是null 以下代碼的輸出結果是什么:
Boolean b1 = new Boolean(true);Boolean b2 = new Boolean(true);if(b1 == b2)
if(b1.equals(b2))
System.out.println(“a”);
else
System.out.println(“b”);
else
if(b1.equals(b2))
System.out.println(“c”);
else
System.out.println(“d”);
選出正確的答案: A a B b C c D d
給出以下代碼:
switch(m){ case 0:System.out.println(“0”);break;case 1:System.out.println(“1”);break;case 2:System.out.println(“2”);break;case 3:System.out.println(“3”);
break;default:System.out.println(“other”);}
當m是何值時會輸出2,選出所有可能的答案:A 0 B 1 C 2 D 3 E 4 F 以上都不對
參考以下代碼塊
outer: for(int i = 1;i <3;i++)
{ inner: for(j = 1;j < 3;j++)
{ if(j==2)
continue outer;
System.out.println(“i = ” +i “, j = ” + j);
}
}
下列哪些會被輸出到控制臺 A i = 1, j = 1 B i = 1, j = 2 C i = 1, j = 3 D i = 2, j = 1 E i = 2, j = 2
查看以下代碼:
class Test{ public static void main(String[] args){
try{
return;
}catch(Exception e){
System.out.println(“Exception”);
}finally{ System.out.println(“Finally”);} } }
會發生什么:
A 編譯錯誤,main方法不能返回任何值 B 打印出“Exception”
C 打印出“Exception”和“Finally” D 打印出“Finally”
如果s1的定義為:String s1 = “phenobarbital”;
那么執行如下代碼后s2的值是什么: String s2 = s1.substring(3, 5);A null B “eno” C “enoba” D “no”
看如下代碼:
class A {}
class B extends A {} class C extends A {} public class Q3ae4 {
public static void main(String args[]){
A x = new A();
B y = new B();
C z = new C();
// insert statement here
} } 在insert statement here處插入如下選項中的代碼,哪些代碼會引起程序運行產生runtime異常: A x = y;B z = x;; C y =(B)x。D z =(C)y;; E y =(A)y;;
查看如下代碼:
1: public void aMethod { 2: 3:
if(Condition){ 4:
5:
} 6: 7: } 如果上面代碼中的Condition為true應該拋出MyException類型的異常,那么哪些答案的描述是正確的:
A在第4行添加throw new Exception();
B在第4行添加throws new MyException()。C在第6行添加throw new MyException(); D在第2行添加throws new Exception(); E 在第1行添加throws MyException
譯和運行以下代碼時會發生什么:
public class Test{
static void throwMethod(){
System.out.println(“inside ThrowMethod”);
throw new IllegalAccessException(“demo”);
} //throwMethod public static void main(String[] args){ try{
throwMethod();}catch(IllegalAccessException e){ System.out.println(“Caught “ + e);
}//catch }//main }
選出正確的答案 A 編譯錯誤。B 運行時錯誤
C 編譯通過,但沒輸出
D 輸出Inside throwMethod 接著輸出caught: java.lang.IllegalAccessException:demo
給出以下代碼:
public static void main(String[] args){ int i = 1;int j = 10;
do{ if(i >j)
continue;
j--;}while(++i < 6);
System.out.println(“i=” +i+” j=” + j);
}//main
下列哪些會被輸出: A i=4 j=5 B i=5 j=6 C i=5 j=5 D i=4 j=6 E i=6 j=5
39當運行下面程序時會發生什么: class Tester{ int var;Tester(double var){
this.var =(int)var;
}
Tester(int var){ this(“hello”);}
Tester(String s){ this();System.out.println(s);}
Tester(){ System.out.println(“good-bye”);}
public static void main(String[] args){ Tester t = new Tester(5);} }
選出所有正確答案 A 沒有任何輸出 B 輸出“hello” C 輸出5 D 輸出“hello”和”good-bye” E 輸出“good-bye”和”hello”
40給出下列代碼 public class Base{ int w,x,y,z;public Base(int a,int b){
x = a;
y = b;} public Base(int a,int b,int c,int d){ //設置x = a;y = b w =d;z =c;} } 在//設置x = a;y = b處可以添加什么代碼,選出所有正確的答案:
A Base(a,b);B x =a,y =b;C x =a;y=b;D this(a,b);41 如果你試圖編譯以下代碼并執行B類中的main方法時會發生什么,選擇唯一的正確答案
class A {
int i;
A(int i){
this.i = i * 2;
} }
class B extends A {
public static void main(String[] args){
B b = new B(2);
}
B(int i){
System.out.println(i);
} } A 實例變量i被設置為4 B 實例變量i被設置為2 C 實例變量i被設置為0
D 編譯出錯
42編譯和運行以下代碼會發生什么
1.class A {
2.public int i=5;
3.A(int initi){ i = initi;}
4.public static void main(String[] args){ 5.final A theA = new A(10);6.theA.i = 15;
7.System.out.println(theA.i);8.} 9.}
A 第六行編譯出錯 B 程序輸出”5”;C 程序輸出”10”;D 程序輸出”15”;
43關于try、catch、finally塊,下列描述正確的是:
A try塊后面必須總是跟著catch塊
B try塊后面可以跟catch塊或者finally塊,也可以兩者都有。
C catch必須總是和try塊關聯。
D 如果沒有try塊的話,finally塊永遠不可以單獨出現。
E 上面沒有一個是正確的
44查看下面的代碼,編譯個運行該代碼將會產生什么結果:
public static void main(String args[]){ int a = 5;
System.out.println(cube(a));}
int cube(int theNum){
return theNum * theNum * theNum;}
A 因為cube在java.lang.Math類中已經定義了,所以編譯錯誤
B 因為cube不是靜態類型的,所以編譯錯誤。C 編譯成功,但是會拋出算術異常 正常運行,打印出”125”
D 正常運行,打印出”125”
45定義一個八進制的值17,下面哪些方法是正確的:
A private final int theNumber = 0x17;B private final int theNumber = 017;C public int theNumber = 017;
D public int theNumber =(octal)17;E
public int THE_NUMBER = 017;
給定如下接口:
interface A {
int method1(int i);
int method2(int j);} 下面哪些類實現了這個接口而且不是抽象類: A class B implements A {
int method1(){ }
int method2(){ } }
B class B {
int method1(int i){ }
int method2(int j){ } }
C class B implements A {
int method1(int i){ }
int method2(int j){ } }。
D class B extends A {
int method1(int i){ }
int method2(int j){ } }
E class B implements A {
int method2(int j){ }
int method1(int i){ } }。
編譯和運行以下代碼時會發生什么:
class Mystery{
String s;
public static void main(String[] args){
Mystery m = new Mystery();
m.go();}//main void Mystery(){ s = “constructor”;} void go(){ System.out.println(s);} }//Mystery 選出正確答案 A 編譯錯誤
B 運行時拋出異常 C 運行時沒有任何輸出 D 運行時輸出”constructor” E 運行時輸出”null”
48編譯以下代碼時會發生什么錯誤:
class A{ private int x;public static void main(String[] args){
new B();}
class B{ B(){
System.out.println(x);
} } }
A 類B試圖訪問它外部類A里面的私有變量
B 類A在沒有創建A的實例前試圖創建一個類B的實例。
C 類B的構造方法必須被申明成public
49試圖編譯和運行以下代碼時會發生什么
1.class Fish { }
2.class Shark extends Fish { } 3.class Guppy extends Fish { } 4.5.public class Ocean {
6.public static void main(String[] args){ 7.Fish f = new Shark();8.Guppy g =(Guppy)f;9.}
10.}
A 第七行編譯出錯.B 第八行編譯出錯
C
第七行運行時拋出異常 D
第八行運行時拋出異常 E
程序正確運行
如果下面的代碼段被成功編譯和執行,將會顯示什么結果:
class Test{
public static void main(String [] args){
Base b = new Subclass();
System.out.println(b.x);
System.out.println(b.method());
} } class Base{
int x = 2;
int method(){
return x;
} }
class Subclass extends Base{
int x = 3;
int method(){
return x;
} }
A 什么都沒有,因為對象b沒有使用正確的方法構造對象,所以代碼編譯錯誤 B 2 3。C 2 2 D 3 3 E 3 2
51下面哪些方法申明能夠被放在注釋處,選出所有正確的答案
class Base{ public void aMethod(int i){} } public class Scope extends Base{ public static void main(String[] args){} //注釋 } A void aMethod(int i)throws Exception{} B void aMethod(long i)throws Exception{} C void aMethod(long i){} D public void aMethod(int i)throws Exception
52給出以下代碼:
public class Test{ public static void test(){
this.print();} public static void print(){ System.out.println(“Test”);}
public static void main(String[] args){ test();}
}
編譯和運行這個類時會發生什么: A 輸出Test
B 運行時異常,因為對象沒有創建出來 C 沒有任何輸出
D 運行時異常,因為找不到test方法
E 運行時異常,因為this變量只能在一個實例中使用
F 編譯錯誤,因為在test方法中使用this變量。
53給出以下代碼:
class Happy{ public int getLength(){
System.out.println(“int version”);
return 1;} }
class Life extends Happy{ public long getLength(){
System.out.println(“long version”);
return 1;}
public static void main(String[] args){ Happy e = new Life();e.getLength();} }
下列正確的是: A 輸出int version B 輸出 long version C 編譯錯誤 D 運行期異常 E 沒有輸出
查看下面的代碼:
class Tree{}
class Pine extends Tree{} class Oak extends Tree{} public class Forest
{ public static void main(String[] args)
{ Tree tree = new Pine();
if(tree instanceof Pine)
System.out.println(“Pine”);
if(tree instanceof Tree)
System.out.println(“Tree”);
if(tree instanceof Oak)
System.out.println(“Oak”);
else System.out.println(“Oops”);
} } 選擇所有會被打印出來的內容: A Pine。B Tree。C Forest D Oops。
E 沒有打印任何內容
55什么情況下一個線程會停止執行
a)一個具有更高優先級的線程開始執行的時候 b)線程的wait方法被調用 c)線程的yield方法被調用 d)線程pause方法被調用 e)線程的sleep方法被調用
給定下面的類:
class Counter {
public int startHere = 1;
public int endHere = 100;
public static void main(String[] args){
new Counter().go();
}
void go(){
// A
Thread t = new Thread(a);
t.start();
} } 哪幾個答案可以被放在//A處,使得程序執行的時候能夠從startHere數到endHere: A.Runnable a = new Runnable(){
public void run(){
for(int i = startHere;i <= endHere;i++){
System.out.println(i);
}
} }。
B.a implements Runnable {
public void run(){
for(int i = startHere;i <= endHere;i++){
System.out.println(i);
}
} };
C.Thread a = new Thread(){
public void run(){
for(int i = startHere;i <= endHere;i++){
System.out.println(i);
}
} }。
57試圖編譯和運行以下代碼時會發生什么? class Test implements Runnable{ int i = 0;public int run(){
while(true){
i++;System.out.println(“i=”+i);
} } }
選出正確的答案
A 編譯成功,run方法打印出i的值
B 編譯成功,調用start方法后打印出i的值 C 編譯錯誤
D 編譯錯誤,因為while的參數不能是true
給出下面代碼,會輸出什么結果? class ValHold{ public int i = 10;}
public class ObParm{
public static void main(String argv[]){ ObParm o = new ObParm();o.amethod();}
public void amethod(){ int i = 99;
ValHold v = new ValHold();v.i=30;
another(v,i);
System.out.println(v.i);}//End of amethod public void another(ValHold v, int i){ i=0;v.i = 20;ValHold vh = new ValHold();v = vh;System.out.println(v.i+ “ ”+i);}//End of another } A 10,0, 30 B 20,0,30 C 20,99,30 D 10,0,20
public class test{ private static int j = 0;private static boolean methodB(int k){
j += k;
return true;
} public static void methodA(int i){
boolean b;
b = i < 10 | methodB(4);
b = i < 10 | methodB(8);} public static void main(String[] args){ methodA(0);System.out.println(j);} }
編譯和運行時會發生什么?
A 輸出“0” B 輸出 “4” C 輸出 “8” D 輸出 “12” E 編譯錯誤
class Test {
public static void main(String[] args){
Thread t = new Thread(new RunHandler());
t.start();
} } 下列選項中哪些是正確的:
A RunHandler 必須實現.Runnable接口 B RunHandler 必須繼承Thread類
C
RunHandler必須提供一個run(),它的訪問權限應該是public,返回類型是void
D RunHandler 必須提供一個init方法
61查看以下代碼,編譯和運行時會發生什么 public class Bground extends Thread{ public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for(int i = 0;i <10;i++){
System.out.println(“Value of i = ” + i);
}
} }
A 編譯錯誤 B 運行錯誤
C 編譯成功,輸出0到9 D 編譯成功,但沒輸出。
62在下面代碼的注釋處加入什么代碼會輸出“running” class Test implements Runnable{ public static void main(String[] args){
Test rt = new Test();
Thread t = new Thread(rt);//注釋
}
public void run(){ System.out.println(“running”);}
void go(){ start(1);}
void start(int i){ } }
A System.out.println(“running”);B rt.start();C rt.go();D rt.start(1);
第三篇:JAVA程序員筆試題目(模版)
JAVA程序員筆試題目
1、有一個Vector對象,其中每一個元素都是一個String對象,請用For循環或者While循環輸出Vector中的元素,要求格式為:“第i個元素為:aaa”
2、答:
3、Iterator it=Vector.iterat();
4、While(it.hasNext()){
5、String temp=(String)it.next();System.out.print(第一個元素為:);System.out.println(temp);6、7、}
8、Jsp有哪些內置對象,作用分別是什么?
9、答:request,response,pageContext,session,application,out.config,page,exception等
10、在try {}里面有一個return語句,那么緊跟在try{}后的finally{}里面的 code是否會被執行,是什么時候執行,在return之前還是之后。答:
11、面向對象的基本特征是什么?
12、答:繼承,封裝,多態,13、頁面之間傳遞參數的方法有哪些?
14、答:利用request,pageContext,session,application,cookie對象都可以
15、Servlet中什么時候調用doGet()和doPost()?這兩種方法有什么不同?
16、答:當表單是用get方法提交時,調用doGet(),反之調用doPost();
17、頁面中有一個名稱為unitprice的type=text的對象。要求輸入的數據不能為空,寫一個函數實現該功能,如果為空是給出提示。(用JavaScript語言寫出)答: