Студопедия

КАТЕГОРИИ:

АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника


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




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();

 

 

30. Given:

10. abstract public class Employee {

11. protected abstract double getSalesAmount();

12. public double getCommision() {

13. return getSalesAmount() * 0.15;

14. }

15. }

16. class Sales extends Employee {

17. // insert method here

18. }

Which two methods, inserted independently at line 17, correctly complete the Sales class? (Choose two.)

A. double getSalesAmount() { return 1230.45; }

B. public double getSalesAmount() { return 1230.45; }

C. private double getSalesAmount() { return 1230.45; }

D. protected double getSalesAmount() { return 1230.45; }

 

31. Given:

10. interface Data { public void load(); }

11. abstract class Info { public abstract void load(); }

 

Which class correctly uses the Data interface and Info class?

A. public class Employee extends Info implements Data {

public void load() { /*do something*/ }

}

B. public class Employee implements Info extends Data {

public void load() { /*do something*/ }

}

C. public class Employee extends Info implements Data {

public void load() { /*do something */ }

public void Info.load() { /*do something*/ }

}

D. public class Employee implements Info extends Data {

public void Data.load() { /*d something */ }

public void load() { /*do something */ }

}

E. public class Employee implements Info extends Data {

public void load() { /*do something */ }

public void Info.load(){ /*do something*/ }

}

F. public class Employee extends Info implements Data{

public void Data.load() { /*do something*/ }

public void Info.load() { /*do something*/ }

}

 

 

32. Which two classes correctly implement both the java.lang.Runnable and the java.lang.Clonable interfaces? (Choose two.)

A. public class Session implements Runnable, Clonable {

public void run();

public Object clone();

}

B. public class Session extends Runnable, Clonable {

public void run() { / do something */ }

public Object clone() { / make a copy */ }

}

C. public class Session implements Runnable, Clonable {

public void run() { / do something */ }

public Object clone() { /* make a copy */ } }

D. public abstract class Session implements Runnable, Clonable {

public void run() { / do something */ }

public Object clone() { /*make a copy */ } }

E. public class Session implements Runnable, implements Clonable {

public void run() { / do something */ }

public Object clone() { / make a copy */ }

}

 


Поделиться:

Дата добавления: 2015-09-13; просмотров: 69; Мы поможем в написании вашей работы!; Нарушение авторских прав





lektsii.com - Лекции.Ком - 2014-2024 год. (0.007 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав
Главная страница Случайная страница Контакты