This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hello - I'm new here, so please bear with me... Trying to figure out the difference between declaring variables in the following areas:
"class-level" (instance/class variables)
within default constructor
I think it starts to really matter when I start extending the class, since a subclass will have it's own default constructor, so if I want particular variables to be accessible to all subclasses, then they need to be declared at the "class-level". Just need a little reassurance of this though.
Absolutely. Any variable that is declared in a method, including a constructor, is available only within the scope of that method. You can initialize the value of variables in a constructor (indeed, that's one of their primary purposes), but the variables must be declared as class or instance variables to be accessible to methods of the class or derived classes. hth, bear