java练习题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1 When you compile a java program you should use command:

A java *.java

B javab *.java

C javac *.java

D javad *.java

2 Which of the following lines will compile without error.

A float f=1.3; double

B char c="a"; string

C boolean b=null;

D double d=1.3;

3 Which statement will compile wrong:

A if(3>5)System.out.println("hello");

B if (3)System.out.println("hello");

C if(true)System.out.println("hello");

D if(false)System.out.println("hello");

4 Consider the following code:

Integer s = new Integer(9);

Integer t = new Integer(9);

Long u = new Long(9);

Which test would return true?

A (s.equals(new Integer(9))

B (s.equals(9))

C (s==u)

D (s==t)

5 All of the following are wrapper classes except:

A String

B Integer

C Character

D Double

6 When you use the assignment operator with variables of a class type, you are assigning a:

A value

B primitive type

C local variable

D reference

7 A class design requires that a particular member variable must be accesible for direct access by any subclasses of this class, otherwise not by classes which are not members of the same package. What should be done to achieve this?

A. The variable should be marked public

B. The variable should be marked private

C. The variable should be marked protected

D. The variable should have no special access modifier

8 Given:

class A {

A() { }

}

class B extends A {

}

Which statement is true?

A. Class B's constructor is public.

B. Class B's constructor has arguments.

C. Class B's constructor includes a call to this().

D. Class B's constructor includes a call to super().

9 class super {

public int getLength() {return 4;}

}

public class Sub extends Super {

public long getLength() {return 5;}

public static void main (String[]args) {

super sooper = new Super ();

Sub sub = new Sub();

System.out.printIn(sooper.getLength()+ "," + sub.getLength() };

}

What is the output?

A.4, 4

B.4, 5

C.5, 4

D.the code will not compile

10 in java which one is not a Layout Management class:

A. BorderLayout

B. FlowLayout

C. CardLayout

D. LayoutManage

11 which one can construct a BufferedOutputStream object:

A. new BufferedOutputStream();

B. new BufferedOutputStream("o.txt");

C. new BufferedOutputStream(new Writer("o.txt"));

D. new BufferedOutputStream(new FileOutputStream("o.txt"));

12 Which one is valid declaration within an interface definition?

A. public void methoda();

B. protected void methoda(double d1);

C. public final double methoda();

D. private void methoda(double d1);

13 Given:

1. public class Foo {

2. public static void main(String[] args) {

3. try {

4. return;

5. } finally {

6. System.out.println( "Finally" );

7. }

8. }

9. }

What is the result?

A. Finally

B. Compilation fails.

C. The code runs with no output.

D. An exception is thrown at runtime.

14 Given:

public class A {

public int add(int a, int b){

return a+b

}

}

Which one overload the add method?

A. double add (int a, int b){ return a+b; }

B. public double add(double ax, double by) { return ax+by; }

C. public double add(int ax, int by) { return ax+by; }

D. public int add(int ax, int by){ return ax+by;}

15 Given:

1. public interface Foo {

2. int k = 4;

3. }

Which one is equivalent to line 2?

A.final int k = 4;

B abstract int;

相关文档
最新文档