AmbitionBox

Discover Best Places to work in India

Java Programming

Java Programming Questions and Answers

Showing 21 - 30 of 150 questions

21
classBoo 
{
    Boo(String s) { }
    Boo() { }
}
classBarextendsBoo 
{
    Bar() { }
    Bar(String s) {super(s);}
    void zoo() 
    {
    // insert code here
    }
}
which one create an anonymous inner class from within class Bar?
a

Boo f = new Boo(24) { };

b

Boo f = new Bar() { };

c

Bar f = new Boo(String s) { };

d

Boo f = new Boo.Bar(String s) { };

correct answer b
22

1.What happens when the following code is compiled and run. Select the one correct answer.


for(int i = 1; i < 3; i++)
  for(int j = 3; j > i; j--)
     assert i!=j {System.out.println(i); }

 

a

The number 1 gets printed with AssertionError

b

The number 1 gets printed with AssertionError

c

The class compiles and runs, but does not print anything

d

The program generates a compilation error

correct answer d
23

What happens when the following code is compiled and run. Select the one correct answer.


for(int i = 1; i < 3; i++)
  for(int j = 3; j >= 1; j--)
     assert i!=j : i;

 

a

The class compiles and runs, but does not print anything

b

The number 1 gets printed with AssertionError

c

The number 2 gets printed with AssertionError

d

The number 3 gets printed with AssertionError

correct answer b
24
    1. What happens when the following code is compiled and run. Select the one correct answer.


for(int i = 1; i < 4; i++)
  for(int j = 1; j < 4; j++)
    if(i < j)
       assert i!=j : i;

 

 

a

The class compiles and runs, but does not print anything

b

The number 1 gets printed with AssertionError

c

The number 2 gets printed with AssertionError

d

The number 3 gets printed with AssertionError

correct answer a
25

Which of the following statement is true about the assert statement. Select the one correct answer

 

a

If a Java class contains assert statements, then it must be compiled with -1.4 option

b

When a program having assertions is run, -assertion option must be specified, otherwise the assertions get ignored

c

A possible syntax of assert statement is
 assert logical_expression If logical_expression evaluates to true, the program generates an AssertionError

d

The program terminates on its first AssertionError

correct answer d
26

Which all lines are part of the output when the following code is compiled and run. Select the one correct answer.


public class test {
	public static void main(String args[]) {
	    for(int i = 0; i < 3; i++) {
		for(int j = 3; j <= 0; j--) {
		    if(i == j) continue;
		    System.out.println(i + " " + j);
		}
	    }
 	}
}

 

a

1 1

b

2 3

c

3 0

d

The program does not print anything

correct answer d
27

What happens when the following class is compiled and run. Select one correct answer.


public class test {
	public static void main(String args[]) {
		int x = 0, y = 1, z;
		if(x) 
		    z = 0;
		else
		    z = 1;

		if(y) 
		    z = 2;
		else
		    z = 3;
		System.out.println(z); 		
	}
}

 

a

The program prints 0

b

The program prints 1

c

The program prints 2

d

The program does not compile because of problems in the if statement.

correct answer d
28

What all gets printed when the following gets compiled and run. Select the two correct answers.


public class example {
	public static void main(String args[]) {
		int x = 0;
		if(x > 0) x = 1;

		switch(x) {
		case 1: System.out.println(1);
		case 0: System.out.println(0);
		case 2: System.out.println(2);
			break;
		case 3: System.out.println(3);
		default: System.out.println(4);
			break;
		}
	}
}

 

 

a

0

b

1

c

2

d

3

correct answer a,c
29

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


public class test {
	public static void main(String args[]) {
		int i = -1;
		i = i >> 1;	 
 		System.out.println(i);
	}
}

 

 

a

63

b

-1

c

0

d

127

correct answer b
30

Which of the following are correct. Select all correct answers.

 

a

Java provides two operators to do left shift - << and <<<

b

>> is the zero fill right shift operator

c

>>> is the signed right shift operator

d

For positive numbers, results of operators >> and >>> are same

correct answer d
Select a company to compare with

vs

Similar Companies