2011년 2월 24일 목요일

JAVA JAVA... 잡아

1. package foo;

2.

3. import java.util.Vector;

4.

5. private class MyVector extends Vector {

6. int i = 1;

7. public MyVector() {

8. i = 2;

9. }

10. }

11.

12. public class MyNewVector extends MyVector {

13. public MyNewVector() {

14. i = 4;

15. }

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

17. MyVector v = new MyNewVector();

18. }

19. }

What is the result?

A. Compilation succeeds.

B. Compilation fails because of an error at line 5.

C. Compilation fails because of an error at line 6.

D. Compilation fails because of an error at line 14.

E. Compilation fails because of an error at line 17.


비 : 생성자는 클래스의 접근제한자와 일치해야함.




1. class TestSuper {

2. TestSuper(int i) { }

3. }

4. class TestSub extends TestSuper{ }

5. class TestAll {

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

7. new TestSub();

8. }

9. }

Which is true?

A. Compilation fails.

B. The code runs without exception.

C. An exception is thrown at line 7.

D. An exception is thrown at line 2.


컴파일 에러. 생성자가 없을 때는 부모의 디폴트 생성자를 호출하는데 인자가 있는 생성자 만 있기에.



10. int i = 0;

11. for (; i <4; i += 2) {

12. System.out.print(i + "");

13. }

14. System.out.println(i);

What is the result?

A. 0 2 4

B. 0 2 4 5

C. 0 1 2 3 4

D. Compilation fails.

E. An exception is thrown at runtime.



0, 2 찍고 후처리로 4 되었을 때 이탈하게 된다.
그리고 4를 찍고 종료.




댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

UPBIT is a South Korean company, and people died of suicide cause of coin investment.

 UPBIT is a South Korean company, and people died of suicide cause of coin. The company helps the people who control the market price manipu...