angsdy
Nov 24, 2014, 05:13 PM
So I have the following code in Java:
public class State
{
public static void main(String[] args)
{
final int DIV = 2;
int number;
int counter;
{
// *a*
number = 10;
int y = 12;
number += y;
// *b*
}
final double d;
{
counter = 1;
double a = 2.0;
// *c*
{
d = a + counter++;
// *d*
}
}
number = number / DIV;
// *e*
}
}
Now at the lines //*a*, *b*,. *e* I am supposed to stop and list all the current variables and their visibility. I gave this a shot but I'm not really sure I'm doing this right so I would really appriciate some help. This is what My opinion so far:
*a* - DIV = 2 and has the visibility/state of final
*b* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
*c* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
*d* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
d = 3.0 final
*e* - DIV = 2 and has the visibility of final
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
d = 3.0 final
number = 11 default
This is what I thought of the problem. Thank you in advance.
public class State
{
public static void main(String[] args)
{
final int DIV = 2;
int number;
int counter;
{
// *a*
number = 10;
int y = 12;
number += y;
// *b*
}
final double d;
{
counter = 1;
double a = 2.0;
// *c*
{
d = a + counter++;
// *d*
}
}
number = number / DIV;
// *e*
}
}
Now at the lines //*a*, *b*,. *e* I am supposed to stop and list all the current variables and their visibility. I gave this a shot but I'm not really sure I'm doing this right so I would really appriciate some help. This is what My opinion so far:
*a* - DIV = 2 and has the visibility/state of final
*b* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
*c* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
*d* - DIV = 2 and has the visibility of final
number = 22 and has visibilty default
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
d = 3.0 final
*e* - DIV = 2 and has the visibility of final
y = 12 visibilty default
counter = 1 default
double a = 2.0 default
d = 3.0 final
number = 11 default
This is what I thought of the problem. Thank you in advance.