AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 11 - 20 of 37 questions

11

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		int x,y;
		x = 1 & 7;
		y = 3 ^ 6;
		System.out.println(x + " " + y);
	}
}

 

 

a

1 3

b

1 5

c

1 7

d

3 5

correct answer a,b
12

What gets displayed on the screen when the following program is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		int x,y;
		x = 3 & 5;
		y = 3 | 5;
		System.out.println(x + " " + y);
	}
}

 

 

a

1 3

b

1 5

c

1 7

d

3 5

correct answer a,c
13

What gets printed when the following program is compiled and run. Select the one correct answer.



public class test {
	public static void main(String args[]) {
		byte x = 3;
		x = (byte)~x;
		System.out.println(x);
	}
}

 

 

a

3

b

0

c

1

d

-4

correct answer d
14

Which operator is used to perform bitwise inversion in Java. Select the one correct answer

a

~

b

!

c

|

d

^

correct answer a
15

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.


public class ShortCkt {
	public static void main(String args[]) {
		int i = 0;
		boolean t = true;
		boolean f = false, b;
		b = (t | ((i++) == 0));
		b = (f | ((i+=2) > 0));
		System.out.println(i);		
	}
}

 

a

0

b

1

c

2

d

3

correct answer d
16

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.


public class ShortCkt {
	public static void main(String args[]) {
		int i = 0;
		boolean t = true;
		boolean f = false, b;
		b = (t || ((i++) == 0));
		b = (f || ((i+=2) > 0));
		System.out.println(i);		
	}
}

 

a

0

b

1

c

2

d

3

correct answer c
17

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.


public class ShortCkt {
	public static void main(String args[]) {
		int i = 0;
		boolean t = true;
		boolean f = false, b;
		b = (t & ((i++) == 0));
		b = (f & ((i+=2) > 0));
		System.out.println(i);		
	}
}

 

a

0

b

1

c

2

d

3

correct answer d
18

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer.


public class ShortCkt {
	public static void main(String args[]) {
		int i = 0;
		boolean t = true;
		boolean f = false, b;
		b = (t && ((i++) == 0));
		b = (f && ((i+=2) > 0));
		System.out.println(i);		
	}
}

 

a

0

b

1

c

2

d

3

correct answer b

In the second assignment to variable b, the expression (i+=2) does not get evaluated.

19

What gets printed when the following program is compiled and run. Select the one correct answer.


class test {
	public static void main(String args[]) {
		int i,j,k,l=0;
		k = l++;
		j = ++k;
		i = j++;
		System.out.println(i);		
	}
}

 

a

0

b

1

c

2

d

3

correct answer b
20

In the following class definition, which is the first line (if any) that causes a compilation error. Select the one correct answer.


public class test {
	public static void main(String args[]) {
		char c;
		int i;
		c = 'A';		// 1
		i = c;		//2
		c = i + 1;	//3
		c++;		//4
	}
}

 

a

The line labelled 1

b

The line labelled 2

c

The line labelled 3

d

The line labelled 4

correct answer c

It is not possible to assign an integer to a character in this case without a cast.

Select a company to compare with

vs

Similar Companies