Ask Experts Questions for FREE Help !
Ask
    angsdy's Avatar
    angsdy Posts: 1, Reputation: 1
    New Member
     
    #1

    Nov 24, 2014, 05:13 PM
    Java state and visibility problem
    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.

Check out some similar questions!

Java if problem [ 1 Answers ]

public class Employee { public void mainfnt(){ try{ System.out.println("Enter First Name: "); Scanner obj=new Scanner(System.in); String Fname=obj.nextLine(); System.out.println("Enter Last Name: "); String Lname=obj.nextLine(); ...

How do I fix LAN visibility problem? [ 0 Answers ]

I am connected to LAN from my Laptop (Win7-64bit) via wifi. Problem 1: All networking functions OK via IP address but I cannot view the LAN (but sometimes the other computers appear) or connect via computer name (i.e: \\SERVER1 gives a timeout error, but \\192.168.102.55 connects directly)...

Java Swing Problem [ 2 Answers ]

A JComboBox has constructors that can take a Vector or a ComboBoxModel. When I pass a DefaultComboBoxModel to it, and change the contents of the DefaultComboBoxModel, the drop-down list changes as expected. No problem. However, if I pass a Vector to it and change the contents of the...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.