Practice Flow Control –
What will be the output of the program?
int i = 1, j = 10;
do {
if(i > j) {
break;
}
j--;
}
while (++i < 5);
System.out.println("i = " + i + " and j = " + j);
Practice Flow Control –
What will be the output of the program?
int i = 1, j = 10;
do {
if(i > j) {
break;
}
j--;
}
while (++i < 5);
System.out.println("i = " + i + " and j = " + j);
Practice Flow Control –
What will be the output of the program?
int i = l, j = -1;
switch (i) {
case 0, 1: j = 1; /* Line 3 */
case 2: j = 2;
default: j = 0;
}
System.out.println("j = " + j);
Practice Flow Control –
What will be the output of the program?
int i = 0, j = 5;
tp: for(;;) {
i++;
for (;;) {
if(i > --j) {
break tp;
}
}
System.out.println("i =" + i + ", j = " + j);
Practice Flow Control –
What will be the output of the program?
for(int i = 0; i < 3; i++) {
switch(i) {
case 0: break;
case 1: System.out.print("one ");
case 2: System.out.print("two ");
case 3: System.out.print("three ");
}
}
System.out.println("done");
Practice Flow Control –
What will be the output of the program?
for (int i = 0; i < 4; i += 2) {
System.out.print(i + " ");
}
System.out.println(i); /* Line 5 */
Practice Flow Control –
What will be the output of the program?
public class Switch2 {
final static short x = 2;
public static int y = 0;
public static void main(String [] args) {
for (int z=0; z < 3; z++) {
switch (z) {
case x: System.out.print("0 ");
case x-1: System.out.print("1 ");
case x-2: System.out.print("2 ");
}
}
}
}
Practice Flow Control –
What will be the output of the program ?
public class CommandArgsTwo {
public static void main(String [] argh) {
int x;
x = argh.length;
for (int y = 1; y <= x; y++) {
System.out.print(" " + argh[y]);
}
}
}
and the command-line invocation is
java CommandArgsTwo 1 2 3
void start() {
A a = n
Practice Garbage Collections –
void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}
Which of the following are true statements?
Practice Objects and Collections –
Which of the following are true statements?
x = 0;
if (x1.hashCode() != x2
Practice hashCode() method –
x = 0;
if (x1.hashCode() != x2.hashCode() )
x = x + 1;
if (x3.equals(x4) )
x = x + 10;
if (!x5.equals(x6) )
x = x + 100;
if (x7.hashCode() == x8.hashCode() )
x = x + 1000;
System.out.println("x = " + x);
and assuming that the equals() and hashCode() methods are property implemented, if the output is “x = 1111“, which of the following statements will always be true?
Which two statements are true about comparing two instances of the
Practice hashCode() method –
Which two statements are true about comparing two instances of the same class, given that the equals() and hashCode() methods have been properly overridden?
Which statement is true?
Practice Garbage Collections –
Which statement is true?
Which statement is true?
Practice Garbage Collections –
Which statement is true?
Which statement is true?
Practice Garbage Collections –
Which statement is true?
What allows the programmer to destroy an object x ?
Practice Garbage Collections –
What allows the programmer to destroy an object x ?