Operators and Scopes

Quiz Guidelines


True or False


The following code snippet will print 'true'.

short s = Short.MAX_VALUE;
char c = s;
System.out.println( c == Short.MAX_VALUE);

Select 1 option

A. True
B. False

Multiple Choice Question


Assume that a, b, and c refer to instances of primitive wrapper classes. Which of the following statements are correct?

Note: Although primitive wrapper classes are not explicitly mentioned in the exam objectives, we have seen some candidates get questions on this aspect of wrapper classes.

Select 2 options

A. a.equals(a) will always return true.
B. b.equals(c) may return false even if c.equals(b) returns true.
C. a.equals(b) returns same as a == b.
D. a.equals(b) throws an exception if they refer to instances of different classes.
E. a.equals(b) returns false if they refer to instances of different classes.

Multiple Choice Question


Consider the following lines of code:

Integer i = new Integer(42);
Long ln = new Long(42);
Double d = new Double(42.0);

Which of the following options are valid?

Select 3 options

A. i == ln;
B. ln == d;
C. i.equals(d);
D. d.equals(ln);
E. ln.equals(42);

Multiple Choice Question


Consider the following code:

public class Conversion{
public static void main(String[] args){
int i = 1234567890;
float f = i;
System.out.println(i - (int)f);

What will it print when run?

Select 1 option

A. It will print 0.
B. It will not print 0.
C. It will not compile.
D. It will throw an exception at runtime.
E. None of the above.

Multiple Choice Question


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

public class PromotionTest{
public static void main(String args[]){
int i = 5;
float f = 5.5f;
double d = 3.8;
char c = 'a';
if (i == f) c++;
if (((int) (f + d)) == ((int) f + (int) d)) c += 2;

Select 1 option

A. The code will fail to compile.
B. It will print d.
C. It will print c.
D. It will print b
E. It will print a.