Looking for Об'єктно-орієнтоване програмування test answers and solutions? Browse our comprehensive collection of verified answers for Об'єктно-орієнтоване програмування at virt.ldubgd.edu.ua.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
Результат компіляції програмного коду:
public class NewThreadThree implements Runnable {
String name;
Thread t;
NewThreadThree (String і){
name = і;
t = new Thread (this, name);
t.start();
}
public void run() {
try {
System.out.println("Виконання потоку "+ name);
Thread.sleep(200);
}catch (InterruptedException e) {
System.out .println(name + " перервано");
}
System.out .println(name + " завершено");
}
}
public class NewThreadThreeMain {
public static void main(String[] args) {
NewThreadThree o1 = new NewThreadThree("Один");
System.out.println("Стан потоку виконання " + o1.t.isAlive());
try {
o1.t.join();
} catch (InterruptedException e) {
System.out.println("Головний потік перервано");
}
System.out.println("Стан першого потоку виконання " + o1.t.isAlive());
System.out.println("Головний потік завершено");
}
}
Результат виконання програмного коду:
public class Exception {
public static void main(String[] args) {
int d = 1;
int c = 1 – d;
int a = d / c;
}
}Які ключові оператори застосовую в Java для опрацювання виключень?
Що відображає окрема частина трасування стеку «(Exc .java:7)» в наведеному фрагменті:
Exception in thread "main" / Index out of bounds for length
at Package1. Exception.main(Exception.java:7)
Результат компіляції програми:
public class Exc_2 {
public static void main(String[] args) {
int a, b;
try {
a = 0;
b = 2 / a;
System.out.println("Стрічка блоку коду try");
}catch (ArithmeticException e) {
System.out.println("Перехоплено та опрацьовано виключення");
}
System.out.println("Продовження ходу виконання програми");
}
}
Призначення оператора
Для чого служить блок оператора try під час опрацювання виключень?
Результат компіляції програми:
public class MultipleCatches {
public static void main(String[] args) {
try {
int a = 0;
int b = 2 / a;
int c[] = new int [1];
c[2] = 5;
} catch (ArithmeticException e) {
System.out.println("Ділення на нуль: ");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Помилка індексації за межами масиву: ");
}
System.out.println("Після блоку операторів try/catch");
}
}
Результат компіляції програми:
public class FinallyDemo {
static void A() {
try {
System.out.println("В тілі методу A()");
} finally {
System.out.println("Виконання finally в методі A()");
}
}
static void B() {
try {
System.out.println("В тілі методу В()");
return;
} finally {
System.out.println("Виконання finally в методі B()");
}
}
public static void main(String[] args) {
A();
B();
}
}
Для чого служить блок оператора catch під час опрацювання виключень?