Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ques-Только тут иногда ошибки мне встретились, редко, но все же.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
240 Кб
Скачать
☆

24. Click the Exhibit button.

10. interface Foo {

11. int bar();

12. }

13.

14. public class Beta {

15.

16. class A implements Foo {

17. public int bar() { return 1; }

18. }

19.

20. public int fubar( Foo foo) { return foo.bar(); }

21.

22. public void testFoo() {

23.

24. class A implements Foo {

25. public int bar() { return 2; }

26. }

27.

28. System.out.println( fubar( new A()));

29. }

30.

31. public static void main( String[] argv) {

32. new Beta().testFoo();

33. }

34. }

Which three statements are true? (Choose three.)

A. Compilation fails.

B. The code compiles and the output is 2.

C. If lines 16, 17 and 18 were removed, compilation would fail.

D. If lines 24, 25 and 26 were removed, compilation would fail.

E. If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.

F. If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

25. Given:

1. package sun.scjp;

2. public enum Color { RED, GREEN, BLUE }

1. package sun.beta;

2. // insert code here

3. public class Beta {

4. Color g = GREEN;

5. public static void main( String[] argv)

6. { System.out.println( GREEN); }

7. }

The class Beta and the enum Color are in different packages.

Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile? (Choose two.)

A. import sun.scjp.Color.*;

B. import static sun.scjp.Color.*;

C. import sun.scjp.Color; import static sun.scjp.Color.*;

D. import sun.scjp.*; import static sun.scjp.Color.*;

E. import sun.scjp.Color; import static sun.scjp.Color.GREEN;

26. Given:

1. public interface A {

2. String DEFAULT_GREETING = "Hello World";

3. public void method1();

4. }

A programmer wants to create an interface called B that has A as its parent. Which interface declaration is correct?

A. public interface B extends A { }

B. public interface B implements A {}

C. public interface B instanceOf A {}

D. public interface B inheritsFrom A { }

27. Given:

1. class TestA {

2. public void start() { System.out.println("TestA"); }

3. }

4. public class TestB extends TestA {

5. public void start() { System.out.println("TestB"); }

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

7. ((TestA)new TestB()).start();

8. }

9. }

What is the result?

A. TestA

B. TestB

C. Compilation fails.

D. An exception is thrown at runtime.

28. Given:

1. interface TestA { String toString(); }

2. public class Test {

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

4. System.out.println(new TestA() {

5. public String toString() { return "test"; }

6. });

7. }

8. }

What is the result?

A. test

B. null

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 1.

E. Compilation fails because of an error in line 4.

F. Compilation fails because of an error in line 5.

29. Given:

11. public abstract class Shape {

12. int x;

13. int y;

14. public abstract void draw();

15. public void setAnchor(int x, int y) {

16. this.x = x;

17. this.y = y;

18. }

19. }

and a class Circle that extends and fully implements the Shape class.

Which is correct?

A. Shape s = new Shape();

s.setAnchor(10,10);

s.draw();

B. Circle c = new Shape();

c.setAnchor(10,10);

c.draw();

C. Shape s = new Circle();

s.setAnchor(10,10);

s.draw();

D. Shape s = new Circle();

s->setAnchor(10,10);

s->draw();

E. Circle c = new Circle();

c.Shape.setAnchor(10,10);

c.Shape.draw();