hi explain with the output
public class Q1eec {
static void
test(int i) {
int j = i/2;
int k = i >>> 1;
assert j == k : i;
}
public static void main(
String[] args) {
test(0);
test(2);
test(-2);
test(1001);
test(-1001);
}
}
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any
thread may call the methods a(), b() and c() at any time?
class Counter {
int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v--; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b");
i.dec(); j.dec(); k.dec();
}
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}
Which statements are true regarding the execution of the following code?
public class Q3a0a {
public static void main(String[] args) {
int j = 5;
for (int i = 0; i<j; i++) {
assert i < j-- : i > 0;
System.out.println(i*j);
}
}
}
What will be written to the standard output when the following program is run?
class Base {
int i;
Base() { add(1); }
void add(int v) { i += v; }
void print() { System.out.println(i); }
}
class Extension extends Base {
Extension() { add(2); }
void add(int v) { i += v*2; }
}
public class Qd073 {
public static void main(String[] args) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}