Looking for Програмування мовою Java test answers and solutions? Browse our comprehensive collection of verified answers for Програмування мовою Java at moodle.chnu.edu.ua.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
public abstract class SomeClass implements Runnable {
public final static Object one = new Object (), two = new Object ();
public static void main (String s []) {
Thread t1 = new Thread () {
public void run () {
synchronized (one) {
try {
Thread.sleep (1000);
} Catch (InterruptedException e) {
e.printStackTrace ();
}
synchronized (two) {
System.out.print ( "1");
}
}
}
};
Thread t2 = new Thread () {
public void run () {
synchronized (two) {
synchronized (one) {
System.out.print ( "2");
}
}
}
};
t1.start ();
t2.start ();
}
}
(Java)
int i = 0;
while (i <4) {
System.out.print (i);
if (i> = 2)
try {
throw new ArithmeticException ( "ex");
}
catch (ArithmeticException e) {
System.out.print (i);
break;
}
i ++;
}
(Java)
(Java)
1 class A {
2 final int a = 5;
3 protected double c;
4 protected int q;
5 private int j;
6}
7 class B extends A {
8 int c;
9 B (int b1, int b2) {
10 super ();
11 c = b1;
12}
13}
Object
java.lang
lang
java.lang.Object
(Java)
public abstract class SomeClass implements Runnable {
private Object lock = new Object ();
public void lock () {
synchronized (lock) {
try {
System.out.print ( "1");
lock.wait ();
} Catch (InterruptedException e) { }
}
}
public void unlock () {
synchronized (lock) {
lock.notify ();
System.out.print ( "2");
}
}
public static void main (String s []) {
new Thread (new SomeClass () {
public void run () {
lock ();
}
}). Start ();
new Thread (new SomeClass () {
public void run () {
unlock ();
}
}). Start ();
}
}
(Java)
1 package newpack;
2 class A {
3 int a, b;
4 void sum () {
5 System.out.print (a + b);
6}
7}
8 class B extends A {
9 ...
10}
11 ...