Test 9 1 public class A private String
Test 9
Вопрос 1. public class A { private String run. Now() { return "High"; } static class B extends A { public String run. Now() { return "Low"; } } public static void main(String args[]) { A[] a = new B[] { new B(), new C() }; for (A aa: a) System. out. print(aa. run. Now() + " "); } } class C extends A. B { public String run. Now() { return "Out"; } } a) b) c) d) e) f) High Low Low Out Low High Ошибка компиляции
Вопрос 2. double p = Double. POSITIVE_INFINITY; double n = Double. NEGATIVE_INFINITY; System. out. println( ((long) p > (long) n) + " " + ((int) p > (int) n) + " " + ((short) p > (short) n) + " " + ((char) p > (char) n) + " " + ((byte) p > (byte) n) ); a) true true b) false false c) true false d) true false e) true false f) true false true
Вопрос 3. public class Class. Roll { private Hash. Map students = new Hash. Map(); private void add. Student ( Student stud ) { students. put(stud. get. Name(), stud) ; } a) private void remove. Student( Student stud ) { students. remove( stud. get. Name() ) ; } d) b) c) public boolean change. Roll( int code, Student stud ) { e) switch( code ) { case 1: add. Student( stud ); return true ; f) case 2: remove. Student( stud ); return true ; default : return false ; }} public boolean is. In. Roll(Student stud) { return students. contains. Key(stud. get. Name()); } } class Student{ ………. . } Сделать метод add. Student синхронизированным. Обьяваить поле students как volatile. Сделать класс синхронизированным. Сделать метод change. Roll синхронизированным. Сделать метод remove. Student синхронизированным. Сделать метод is. In. Roll синхронизированным
Вопрос 4. public class Main { public static void var(Integer x, int y) { System. out. println("Integer int"); } public static void var(Object. . . x) { System. out. println("Object"); } public static void var(int. . . x) { System. out. println("int. . . x"); } public static void var(Integer. . . x) { System. out. println("Integer. . . "); } public static void main(String. . . args) { byte i = 0; Integer i 2 = 127; var(i, i 2); } } a) b) c) d) e) Integer int Object Integer. . . int. . . x Ошибка компиляции
Вопрос 5. public class Wrap. Demo{ public static void main(String. . . args){ String str="19"; str. concat(". 5"); Double d = new Double(str); Long l = new Long(str); System. out. println(d. int. Value() + d. double. Value() + l. double. Value()); } } a) Будет напечатано 57. 5 b) Будет напечатано 57. 0 c) Будет напечатано 58. 0 d) Не скомпилируется
Вопрос 7. public class Test implements Runnable { class My. Obj { void wait. Infinity() throws Interrupted. Exception { while (true) wait(); } } Test() {new Thread(this). start(); } public void run() { try { new My. Obj(). wait. Infinity(); } catch (Interrupted. Exception e) { } } public static void main(String[] args) { new Test(); } } a) Ошибка компиляции b) Ошибка времени выполнения c) Программа зациклится d) Ничего из вышеперечисле нного
Вопрос 8. import java. util. *; public class X { public <X> X(X x) { System. out. println("generic constructor"); } public X(X x) { System. out. println("simple constructor"); } public X() { } public static void main(String args[]) { X x = new X(new Integer(5)); X x 1 = new X(x); } } a) simple constructor b) generic constructor simple constructor c) generic constructor d) simple constructor generic constructor e) Ошибка компиляции
Вопрос 9. public class Test { private String hello. String ="Hello. "; public Test(int i) { class Inner { public Inner(String str) { // Вставьте код } } Inner inner = new Inner("Goodbye. "); } } a) System. out. println(Test); b) System. out. println(i); c) System. out. println( String. value. Of(i)); d) System. out. println( Test. this. hello. String);
Вопрос 10. a) public class Test { b) public static void main(String[] args) { Parent c = new Child(); c) c. sop(); } } class Parent { private Parent() { } public static void sop() { System. out. println("Parent's static sop"); d) } } class Child extends Parent { public static void sop() { System. out. println("Child'd static sop"); } } Child'd static sop Parent's static sop Компиляция будет успешной, но код ничего не напечатает Произойдет ошибка компиляции
- Slides: 11