java 细节3

 

overload没有访问控制限制。

 

澄清一个概念!!重载??还是重写?

 

重载应该叫overload,重写叫override 

 

 

Which two are valid examples of method overriding? (Choose Two) 

A. float getVar ( ) { return x;}

B. public float getVar ( ) { return x;}

C. float double getVar ( ) { return x;}

D. protected float getVar ( ) { return x;}

E. public float getVar (float f ) { return f;}

 

Answer B,D

 

 

D. public class Species { }

public class Animal (private Species species;)

E. interface Component { }

Class Container implements Component (

         Private Component[ ] children;

 

 

Answer D,E

is a 是继承的关系,has a 是调用的关系。

 

 

Given:

1. package foo;

2. 

3. public class Outer (

4.    public static class Inner (

5.    )

6. )

 

Which statement is true?

A. An instance of the Inner class can be constructed with “new Outer.Inner ()”

B. An instance of the inner class cannot be constructed outside of package foo

C. An instance of the inner class can only be constructed from within the outer class

D. From within the package bar, an instance of the inner class can be constructed with “new inner()”

 

 

Answer A

 

 

 

 

 

 

Click the exhibit button:

1.  public class test( 

2.  public int aMethod(){

3. static int i=0; 

4.  i++; 

5.  return I; 

6.  ) 

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

8.  test test = new test(); 

9.  test.aMethod(); 

10. int j = test.aMethod(); 

11. System.out.printIn(j); 

12. }

13. }     

 

What is the result?

A. Compilation will fail.

B. Compilation will succeed and the program will print “0”.

C. Compilation will succeed and the program will print “1”.

D. Compilation will succeed and the program will print “2”.

 

 

Answer A

问题出现在第3行,静态变量属于类,不能在方法中定义.

 

135.

Click the exhibit button:

1. public class SyncTest{ 

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

3. final StringBuffer s1= new StringBuffer(); 

4. final StringBuffer s2= new StringBuffer(); 

5. new Thread ()   { 

6.   public void run() { 

7.    synchronized(s1) { 

8.         s2.append(“A”); 

9.          synchronized(s2) { 

10.   s2.append(“B”); 

11.     System.out.print(s1); 

12.       System.out.print(s2); 

13.       } 

14.   } 

15.   }   

16. }.start(); 

17. new Thread() { 

18.   public void run() { 

19.     synchronized(s2) { 

20.       s2.append(“C”); 

21.       synchronized(s1) { 

22.         s1.append(“D”); 

23.         System.out.print(s2); 

24.         System.out.print(s1); 

25.        } 

26.       } 

27.      } 

28.    }.start(); 

29.   } 

30. } 

 

Which two statements are true? (Choose Two) 

A. The program prints “ABBCAD”

B. The program prints “CDDACB”

C. The program prints “ADCBADBC”

D. The output is a non- deterministic point because of a possible deadlock condition

E. The output is dependent on the threading model of the system the program is running on. 

 

ANSWER:D,E

 

Click the exhibit button:

1. class A { 

2. public byte getNumber () { 

3.   return 1; 

4.   } 

5. } 

6.   

7. class B extends A { 

8. public short getNumber() { 

9. return 2; 

10. )

11.   

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

13.    B b = new B (); 

14.      System.out.printIn(b.getNumber())    

15.   } 

16. } 

 

What is the result?

A. Compilation succeeds and 1 is printed.

B. Compilation succeeds and 2 is printed.

C. An error at line 8 causes compilation to fail.

D. An error at line 14 causes compilation to fail.

E. Compilation succeeds but an exception is thrown at line 14.

 

Answer:C

这道题不是overload,也不是override,那就错的呗。

 

 

The default constructor initializes the instance variables declared in the class. 

When a class has only constructors with parameters, the compiler does not create a default constructor.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值