1 / 11

Test 8

Test 8. Вопрос 1. class Class1 {      Class1( int i ) {  System.out.println ("Class1( int )"); } } public class Class2 extends Class1 {     Class2(double d) {  // 1         this(( int ) d); System.out.println ("Class2(double)"); }     Class2( int i ) {  // 2

harrietr
Download Presentation

Test 8

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test 8

  2. Вопрос 1. class Class1 {      Class1(inti) {  System.out.println("Class1(int)"); } } public class Class2 extends Class1 {     Class2(double d) { // 1         this((int) d); System.out.println("Class2(double)"); }     Class2(inti) { // 2 System.out.println("Class2(int)");}     public static void main(String[] args) {         new Class2(0.0);     } } • Class2(int)Class2(double) • Class1(int)Class2(int)Class2(double) • Ошибка компиляции в строке 1 • Ошибка компиляции в строке 2

  3. Вопрос 2. Выведется ли текст, помещенный в блок условного оператора? public static void main(String[] args){ int x = 18; int y = x++;        if (x == 18 && y > 10){ System.out.println("y = " + y); System.out.println("x = " + x);        } } • нет • да

  4. Вопрос 3.  class A {      public void process() {  System.out.print("A "); } }  class B extends A {   public void process()  throws RuntimeException {//1 super.process();       if (true) throw new RuntimeException(); System.out.print("B");   }  public static void main(String[] args) {           try { ((A)new B()).process(); }//2        catch (Exception e) {  System.out.print("Exception "); } }} • A B Exception • A Exception B • A Exception • Exception • Ошибка компиляции в строке 1 • Ошибка компиляции в строке 2

  5. Вопрос 4. Какие из перечисленных методов объявлены корректно? • void modifyTotal(Object ... args) {} • void doAnyth(inti, Object...args) {} • void confirm(Object...args, inti) {} • void setRate(int... i, float... f) {} • void doSmth(Object ...args) {}

  6. Вопрос 5. Выберите все правильные ответы при которых код скомпилируется, если вставить их в строку 1: public class OverrideThrowsTest {     public static void main(String[] args)         // 1     {         A a = new A(); a.method();         A ab = new B(); ab.method();         B b = new B(); b.method();     } } class A {  public void method() throws IOException {} } class B extends A { public void method()  throws FileNotFoundException {} } • throws FileNotFoundException b) throws IOException c) throw Exception d) throws Exception e) код не скомпилируется ни в одном из указанных случаев

  7. Вопрос 6. public class Main {      public static void main(String[] str) {      outer:          for (inti = 0; i < 2; i++) {            for (int j = 0; j < 2; j++) { System.out.println("Hello");                     continue outer;  } System.out.println("outer"); } System.out.println("Good-Bye");} } • Программа будет бесконечно выводить "Hello“ • HelloHelloouterHelloHelloouterGood-Bye • HelloHelloGood-Bye • HelloGood-Bye • Ошибка компиляции

  8. Вопрос 7. public class MyThread extends Thread {     public static void main(String[] args) {         new MyThread().start();     } } • Программа не выведет ничего. • Ничего из перечисленного. • Возникнет ошибка компиляции. • Программа зациклится. • Возникнет исключение во время выполнения.

  9. Вопрос 8. class Main {      public static void main(String[] args) {         switch (new Integer(4)) {             case 4:  System.out.println("4"); break;             default: System.out.println("default"); }     } } • 4 • defualt • Ошибка компиляции • Ошибка времени выполнения

  10. Вопрос 9. class Main {      public static void main(String[] args) {         Integer i = new Integer("10");         if (i.toString().intern() == i.toString().intern()) {             System.out.println("Равный");         } else { System.out.println("Неравный");}     } } • Ошибка компилятора • Выведется “Равный“ • Выведется “Неравный“ • Ни один из вариантов

  11. Вопрос 10. class One {      public static int j = 90;     One(){ j = 12; } } public class Test extends One {     public static void main(String args[]) {         new Test(); System.out.println(One.j);} } • 90 • 12 • Ошибка выполнения • Ошибка компиляции

More Related