Operators and Scopes

Quiz Guidelines

 

Multiple Choice Question

QID: 
312

What will the following class print?

class InitTest{
public static void main(String[] args){
int a = 10;
int b = 20;
a += (a = 4);
b = b + (b = 5);
System.out.println(a+ ", "+b);
}
}

Select 1 option

A. It will print 8, 25
B. It will print 4, 5
C. It will print 14, 5
D. It will print 4, 25
E. It will print 14, 25

Multiple Choice Question

QID: 
311

Which of the following code snippets will print exactly 10?

1. Object t = new Integer(106);
int k = ((Integer) t).intValue()/10;
System.out.println(k);
2. System.out.println(100/9.9);
3. System.out.println(100/10.0);
4. System.out.println(100/10);
5. System.out.println(3 + 100/10*2-13);

Select 3 options

A. 1
B. 2
C. 3
D. 4
E. 5

Multiple Choice Question

QID: 
142

Which of the following statements are true?

Select 2 options

A. System.out.println(1 + 2 + "3"); would print 33.
B. System.out.println("1" + 2 + 3); would print 15.
C. System.out.println(4 + 1.0f); would print 5.0
D. System.out.println(5/4); would print 1.25
E. System.out.println('a' + 1 ); would print b.

Multiple Choice Question

QID: 
141

Which statements about the output of the following programs are true?

public class TestClass{
public static void main(String args[ ] ){
int i = 0 ;
boolean bool1 = true;
boolean bool2 = false;
boolean bool = false;
bool = (bool2 & method1("1")); //1
bool = (bool2 && method1("2")); //2
bool = (bool1 | method1("3")); //3
bool = (bool1 || method1("4")); //4
}
public static boolean method1(String str){
System.out.println(str);
return true;
}
}

Select 2 options

A. 1 will be the part of the output.
B. 2 will be the part of the output.
C. 3 will be the part of the output.
D. 4 will be the part of the output.
E. None of the above

Multiple Choice Question

QID: 
140

Which operators will always evaluate all the operands?

Select 2 options

A. &&
B. |
C. ||
D. ? :
E. %

Pages