What is the result of compiling and executing the following
Java class:
public class ThreadTest extends
Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(
String args []) {
(new ThreadTest()).start();
}
}
a)Compilation will fail in the method main.
b)Compilation will fail in the method run.
c)A warning will be generated for method run.
d)The string "In run" will be printed to standard out.
e)Both strings will be printed to standard out.
f)Nothing will happen.
answer is d.
but i think the output should be e) "in run" and "leaving run"
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
A. Produce a runtime error
B. Produce a compile time error
C. Print out "Total 0"
D. Generate the following as output:
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
Total 30
answer is c . but according to me the answer should be d