What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class If1 {     
static boolean b;
public static void main(String [] args) {
short hand = 42;
if ( hand < 50 && !b ) /* Line 7 */
hand++;
if ( hand > 50 ); /* Line 9 */
else if ( hand > 40 ) {
hand += 7;
hand++;
}
else
--hand;
System.out.println(hand);
}
}

 

public void test(int x) {
int

Loading

Practice Flow Control –

public void test(int x) {
int odd = 1;
if(odd) {/* Line 3 */
System.out.println("odd");
}
else {
System.out.println("even");
}
}

Which statement is true?

What will be the output of the program?


			  		

Loading

Practice Language Fundamentals –

What will be the output of the program?

class Test {     
public static void main(String [] args) {
Test p = new Test();
p.start();
}
void start() {
boolean b1 = false;
boolean b2 = fix(b1);
System.out.println(b1 + " " + b2);
}
boolean fix(boolean b1) {
b1 = true;
return b1;
}
}

 

What is the widest valid returnType for methodA in line 3?

Loading

Practice Language Fundamentals –

What is the widest valid returnType for methodA in line 3?

public class ReturnIt {      
returnType methodA(byte x, double y) /* Line 3 */ {
return (long)x / y * 2;
}
}

 

Which is a valid declarations of a String?

Loading

Practice Language Fundamentals –

Which is a valid declarations of a String?

Which three are valid declarations of a float?

  1. float f1

Loading

Practice Language Fundamentals –

Which three are valid declarations of a float?

  1. float f1 = -343;
  2. float f2 = 3.14;
  3. float f3 = 0x12345;
  4. float f4 = 42e7;
  5. float f5 = 2001.0D;
  6. float f6 = 2.81F;

What will be the output of the program?


			  		

Loading

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 y: System.out.print("0 "); /* Line 11 */
case x-1: System.out.print("1 "); /* Line 12 */
case x: System.out.print("2 "); /* Line 13 */
}
}
}
}

 

What will be the output of the program?


			  		

Loading

Practice Flow Control –

What will be the output of the program?

public class SwitchTest {       
public static void main(String[] args) {
System.out.println("value =" + switchIt(4));
}
public static int switchIt(int x) {
int j = 1;
switch (x) {
case 1: j++;
case 2: j++;
case 3: j++;
case 4: j++;
case 5: j++;
default: j++;
}
return j + x;
}
}

 

What will be the output of the program?


			  		

Loading

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 ");
}
}
}
}

 

What will be the output of the program?


			  		

Loading

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);

 

switch(x) { 
default:

Loading

Practice Flow Control –

switch(x) { 
default:
System.out.println("Hello");
}

Which two are acceptable types for x?

  1. byte
  2. long
  3. char
  4. float
  5. Short
  6. Long

What will be the output of the program?


			  		

Loading

Practice Declarations and Access Control –

What will be the output of the program?

class BoolArray {     
boolean [] b = new boolean[3];
int count = 0;
void set(boolean [] x, int i) {
x[i] = true;
++count;
}
public static void main(String [] args) {
BoolArray ba = new BoolArray();
ba.set(ba.b, 0);
ba.set(ba.b, 2);
ba.test();
}
void test() {
if ( b[0] && b[1] | b[2] )
count++;
if ( b[1] && b[(++count - 2)] )
count += 7;
System.out.println("count = " + count);
}
}

 

What will be the output of the program?


			  		

Loading

Practice Declarations and Access Control –

What will be the output of the program?

class Test  {     
public static void main(String [] args) {
int x= 0;
int y= 0;
for (int z = 0; z < 5; z++) {
if (( ++x > 2 ) || (++y > 2)) {
x++;
}
}
System.out.println(x + " " + y);
}
}