Data Types and Variables

Quiz Guidelines

 

Multiple Choice Question

QID: 
440

Given the following class, which statements can be inserted at line 1 without causing the code to fail compilation?

public class TestClass{
int a;
int b = 0;
static int c;
public void m(){
int d;
int e = 0;    // Line 1
}
}

Select 4 options

A. a++;
B. b++;
C. c++;
D. d++;
E. e++;

Multiple Choice Question

QID: 
439

Given the following declarations:
        int a = 5, b = 7, k = 0;
        Integer m = null;
and the following statements:
        k = new Integer(a) + new Integer(b);  //1
        k = new Integer(a) + b; //2
        k = a + new Integer(b); //3
        m = new Integer(a) + new Integer(b); //4

Executed independent of each other, what will be the value of k (for //1, //2, and //3)
and m (for //4) after execution of each of these statements?

Select 1 option

A. 12    
will not compile
will not compile
12
B. will not compile
will not compile
will not compile
12
C. 12
12
12
D. will not compile
will not compile
will not compile
will not compile 
E. 12
12
12
will not compile

Multiple Choice Question

QID: 
438

Which statements concerning conversion are true?

Select 4 options

A. Conversion from char to long does not need a cast.
B. Conversion from byte to short does not need a cast. 
C. Conversion from short to char needs a cast.
D. Conversion from int to float need a cast.
E. Conversion from byte, char or short to int, long or float does not need a cast.

Multiple Choice Question

QID: 
288

Note: This question may be considered too advanced for this exam.

What will the following code print when run?

public class TestClass{     
public static Integer wiggler(Integer x){      
 Integer y = x + 10;     
  x++;      
 System.out.println(x);       
return y;    }   
 public static void main(String[] args){      
 Integer dataWrapper = new Integer(5);    
  Integer value = wiggler(dataWrapper);      
 System.out.println(dataWrapper+value);    } }

Select 1 option 

A. 5 and 20 
B. 6 and 515 
C. 6 and 20 
D. 6 and 615 
E. It will not compile.

Multiple Choice Question

QID: 
287

Note: This question may be considered too advanced for this exam. 

Given: 

String mStr = "123"; 
long m = // 1 

Which of the following options when put at //1 will assign 123 to m?

Select 3 options 

A. new Long(mStr); 
B. Long.parseLong(mStr); 
C. Long.longValue(mStr); 
D. (new Long()).parseLong(mStr); 
E. Long.valueOf(mStr).longValue();

Pages