Scala
Does <b>th ...
Мова сайту: Українська
Українська
English
Русский
Тести з програмування
Вхід
Реєстрація
Тести з програмування
Теорія
Сніпети
Статті
Головна
Android
Ціни
FAQ
Історія Cosmo
Правила та умови сервісу
Політика конфіденційності
Політика щодо файлів cookie
Зворотній Зв’язок
Does
throw
expression have a result type in Scala?
Yes, it has
No, it has not
Explanation
Although it may seem somewhat paradoxical, in Scala, throw is an expression that has a result type. Technically, an exception throw has type Nothing.
Source:
Exception handling with try expressions
exceptions
Подобається
Ввійдіть
щоб вподобати
Комментувати
Ввійдіть
щоб прокоментувати
Поширити
Tweet
Пов'язані матеріали
What will be the result of the compilation and execution of the following code? 01. class A { 02. public void process() { System.out.print("A,"); } 03. } 04. public class B extends A { 05. public void process() throws IOException { 06. super.process(); 07. System.out.print("B,"); 08. throw new IOException(); 09. } 10. 11. public static void main(String[] args) { 12. try { new B().process(); } 13. catch (IOException e) { System.out.println("Exception"); } 14. } 15. }
What lines will the compilation error occur in: class MyException1 extends Exception { } // 1 class MyException2 extends RuntimeException { } // 2 class A { void m1() { throw new MyException1(); } // 3 void m2() { throw new MyException2(); } // 4 }
What will be the result of the following program compilation and execution? public class Test { public static void main(String[] args) { int myInt = 0; float myFloat = 0; try { float result = myFloat / myFloat; } catch (RuntimeException re) { System.out.println("Exception 1"); } try { float result = myFloat / myInt; } catch (RuntimeException re) { System.out.println("Exception 2"); } try { float result = myInt / myFloat; } catch (RuntimeException re) { System.out.println("Exception 3"); } try { float result = myInt / myInt; } catch (RuntimeException re) { System.out.println("Exception 4"); } } }
Given the following code 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 {} } Select all the answers, for which, if placed into line 1, code will compile.
What will be printed to standard output stream if a tryThis() method throws an IOException? try { tryThis(); return; } catch (IOException x1) { System.out.println("exception 1"); return; } catch (Exception x2) { System.out.println("exception 2"); return; } finally { System.out.println("finally"); }
What will be the result of the following code execution? class A { public void process() { System.out.print("A "); } } class B extends A { public void process() throws RuntimeException { super.process(); if (true) throw new RuntimeException(); System.out.print("B "); } public static void main(String[] args) { try { ((A)new B()).process(); } catch (Exception e) { System.out.print("Exception "); } } }
Тести з
S
cala
Приєднуйся і вивчай Scala
або
Дізнайся більше про
Тести з Scala онлайн
Слідкуй за CodeGalaxy
Мобільний додаток Beta
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
What will be printed out as a result of the following code execution / compilation? class A { public A() { System.out.print("A"); } } class B { public B() { System.out.print("B"); } } class C { public C() { System.out.print("C"); } } public class D extends C { private A objA = new A(); private static B objB = new B(); public D() { System.out.print("D"); } public static void main(String[] args){ new D(); } }
What will be printed out as a result of the following code execution / compilation? public class Test { private String name; Test(String name) { this.name = name; } public void test(final Test test) { test = new Test("three"); } public String toString() { return name; } public static void main(String[] args) { Test t1 = new Test("one"); Test t2 = new Test("two"); t1.test(t2); System.out.println(t2); } }
What will be printed out as a result of the following code execution / compilation? public class Test { static void m(int ... a) { System.out.println("1"); } static void m(Integer ... a) { System.out.println("2"); } public static void main(String[] args) { m(1, 2); } }
What will be printed out as a result of the following code execution / compilation? public class Test { public static void main(String[] args) { ElectricInverter inverter = new ElectricInverter(); int AC = 220; System.out.println(inverter.invert(AC)); } } class ElectricInverter { public static final int AC = ~220; public static final int DC = -110; public static final int GROUND = 0; int invert(int type) { if (type == AC) { return DC; } else if (type == DC) { return AC; } return GROUND; } }
int i = Integer.MAX_VALUE + 10; What is the result of the given line execution?
What happens after the following code is compiled and run: 01: interface TheInterface { 02: void print(); 03: } 04: 05: class TheClass implements TheInterface { 06: public void print() { 07: System.out.println("TheClass"); 08: } 09: } 10: 11: public class ClassConversion { 12: public static void main(String[] args) { 13: TheClass c = new TheClass(); 14: TheInterface i = c; 15: i.print(); 16: } 17: }
Зареєструйся Зараз
або
Підпишись на майбутні тести
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати