Operators and Scopes

Quiz Guidelines


Multiple Choice Question


Which of the following are valid operators in Java?

Select 4 options

A. !
B. ~
C. &
D. %=
E. $

Multiple Choice Question


What will the following code print when run without any arguments ...

public class TestClass {
public static int m1(int i){
return ++i;
public static void main(String[] args) {
int k = m1(args.length);
k += 3 + ++k;

Select 1 option

A. It will throw ArrayIndexOutofBoundsException.
B. It will throw NullPointerException.
C. 6
D. 5
E. 7
F. 2
G. None of these.

Multiple Choice Question


What will be the result of attempting to compile and run the following class?

public class TestClass{
public static void main(String args[ ] ){
int i, j, k;
i = j = k = 9;

Select 2 options

A. The code will not compile because unlike in c++, operator '=' cannot be chained
 i.e. a = b = c = d is invalid.
B. The code will not compile as 'j' is being used before getting initialized.
C. The code will compile correctly and will display '9' when run.
D. The code will not compile as 'j' and 'i' are being used before getting initialized.
E. All the variables will get a value of 9.

Multiple Choice Question


Which of the following statements will compile without any error?

Select 4 options

A. System.out.println("a"+'b'+63);
B. System.out.println("a"+63);
C. System.out.println('b'+new Integer(63));
D. String s = 'b'+63+"a"; 
E. String s = 63 + new Integer(10);