Java Static Modifier

Objectives         Introduction         Commentary         Interactive Exercises


Interactive Exercises
 

Consider the following EC class:

public class EC extends Object {

public int v1, v2;

public static int vs3 = 0;

public EC (int x, int y) {

v1 = x; v2 = y; vs3++;

} // end int,int constructor

public static void main (String args[]){

EC e = null;

int m = 0;

EC e1 = new EC (0, 4);

EC e2 = new EC (2, 9);

EC e3 = new EC (8, 5);

// questions' code

} // end method main

} // end class EC

Determine if each of the following nine code excerpts is legal replacement for the "// question code" line and if so, determine what is the value of the variable m, after the code is executed:

1. m = e1.v1;

   

                

2. m = e2.v1;

   

                        

3. m = e3.v2;

   

                   

4. m = EC.vs3;

   

                             

5. m = v1;

   

                             

6. m = vs3;

   

            

7. e = e2;
m = e.v2;

   

                           

8. e = e3;
e3 = e2;
m = e3.v1;

   

            

9. e = e3;
e3 = e2;
e2 = e;
m = e2.v1;

   

                       


2006 University of Maryland University College home

.