AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 41 - 50 of 150 questions

41

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
42

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
43

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.

44

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
45

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.

46

The signed right shift operator in Java is --. Select the one correct answer.

a

<<

b

>>>

c

>>

d

None of these

correct answer c
47

What is the result of compiling and running the following class. Select the one correct answer.



class Test {

   public void methodA(int i) {

      System.out.println(i); 

   }

   public int methodA(int i) {

      System.out.println(i+1); 

      return i+1; 

   }

   public static void main(String args[]) {

      Test X = new Test();

      X.methodA(5);

   }

}

 

a

The program compiles and runs printing 5

b

The program compiles and runs printing 6

c

The program gives runtime exception because it does not find the method Test.methodA(int)

d

The program give compilation error because methodA is defined twice in class Test

correct answer d
48

Which of the following are valid constructors within a class Test

a

test() { }

b

Test() { }

c

Test(void) { }

d

void Test() { }

correct answer b
49

Which of the following are legal declaration and definition of a method.

a

void method() {}

b

void method(void) {}

c

method(void) {}

d

void method {}

correct answer a
50

What will the result of compiling and executing the following program. Select the one correct answer.

class Test {

    public static void main(String args[]) {

	int arr[] = new int[2];

	System.out.println(arr[0]);

    }

}

 

a

The program does not compile because arr[0] is being read before being initialized

b

The program generates a runtime exception because arr[0] is being read before being initialized

c

The program compiles and prints 0 when executed

d

The program compiles and prints 1 when executed

correct answer c
Select a company to compare with

vs

Similar Companies