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!
Розглянемо наступний приклад.
Exception
+ - LengthException
+ - TooLongException
+ - TooShortException
1 class BaseMeasurer {
2 int measureLength (Dimension d) throws TooLongException {.. }
3 }
4 class DerivedMeasurer extends BaseMeasurer {
5 ___ {
6 }
7 }
Яке з перерахованих нижче виразів можна використовувати в рядку 5 замість знаків підкреслення, щоб код успішно
відкомпільоване?
(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 ...
public abstract class SomeClass implements Runnable {
public static Object lock = new Object ();
public void lock () {
synchronized (lock) {
try {
lock.wait ();
System.out.print ( "1");
} Catch (InterruptedException e) { }
}
}
public void notifyThread () {
synchronized (lock) {
lock.notify ();
}
}
public void unlock () {
synchronized (lock) {
lock.notify ();
System.out.print ( "2");
}
}
public static void main (String s []) {
final SomeClass c = new SomeClass () {
public void run () {
lock ();
notifyThread ();
}
};
final SomeClass c1 = new SomeClass () {
public void run () {
unlock ();
}
};
new Thread (c) .start ();
new Thread (c1) .start ();
}
}
(Java)
1 ...
2 class A extends B {
3 int a, b;
4 void show () {
5 System.out.print (a);
6 System.out.print (b);
7}
8}
public class SomeClass {
public static void main (String s []) {
Calendar cal = new GregorianCalendar ();
cal.set (Calendar.YEAR, 2011);
cal.set (Calendar.MONTH, Calendar.APRIL);
cal.set (Calendar.DAY_OF_MONTH, 30);
cal.add (Calendar.DAY_OF_MONTH, 1);
cal.roll (Calendar.MONTH, 11);
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy MMMM dd");
System.out.println (sdf.format (cal.getTime ()));
}
}
(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 ...
int i = 0;
while (i <5) {
if (i == 0)
throw new NullPointerException ( "first");
if (i == 2)
throw new NumberFormatException ( "second");
i ++;
}
(Java)
1 class A {
2 final int a;
3 protected double c;
4 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}
(Java)