Self Test With Answers

1) Precedence tell us the expression ( 7*3+3*2 ) evaluates to

a) 48
b) 84
c) 27
d) 60                                                                                 ( c )
 

2) The variable x when combined with ++ is best described as

a) an operand being acted upon by a unary operator
b) a operator acted upon by a operand
c) an operand being acted on by two binary operators
d) an unary operand used with a variable operator      ( a )
 

3) Which of the following has the highest precedence

a ) assignment operators
b) post-increment operators
c) addition and subtraction operators
d) short circuit operators                                                 ( b )                
 

4) In the following code what will be printed to console?

    int x=9;
    int y= --x;
    System.out.println( y );

 a) 7
 b) 8
 c) 9
 d) 10                                                                                ( b )                              
 

5) int zz = 6;          ( Hint: Do the binary )
     int k= ~zz;
     System.out.println( k );

a)   5
b) -5
c) -6
d) -7                                                                                  ( d )
 

6) Which of the following is not legal?

a) long lo= ~3L;
b double dx= ~7.0;
c) double dy= float(~1 );
d) int j = int (~l);                                                                ( b )           
 

7)  In the following statement int oxo stores which of the following values?

     int oxo= -8 % -5;

a )  -1
b)    1
c)   -3
d)    3                                                                              ( c )
 

8 ) What number is stored in c as the result of the division?

     int a=  14;
     int b = -5;
     int c=a/b;

a )   -2.8
b)       -3
c)       -2
d)    -3.0                                                                         ( c )
 

9) Which of the following expressions result in a very large positive number?

a)  ( -30 <<  20 )
b)  ( 200 >>   6 )
c)  ( 400 >>> 8 )
d)  (   -3 >>> 2 )                                                           ( d )   
 

10)  The following code will print out which one of the following lettered statements?

        boolean yes=true;
        int y = yes? 7: 11;
           if ( y == (6+1)   |   false ) {
              System.out.println( "Lucky Seven!");
              }
        else{
              System.out.println("I guess not!");
              }
           if (y == 7 &  false  ) {
              System.out.println( "Whatever!");
              }
    else if ( y==11){
              System.out.println("Must be Eleven!");
              }
 

a) Lucky Seven!
b) I guess not!
c) Whatever!
d) Must be Eleven!                                                         ( a )