Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6735

Re: What are the different scopes for Java variables?

From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: What are the different scopes for Java variables?
Date 2011-08-02 00:01 -0700
Organization http://groups.google.com
Message-ID <73d7cd03-cc86-4334-8833-20af4e599427@glegroupsg2000goo.googlegroups.com> (permalink)
References <92093457-2ea3-44c5-a6fc-536842511687@k9g2000yqf.googlegroups.com>

Show all headers | View raw


"Software Engineer" wrote:
> What are the different scopes for Java variables?
> 
> The scope of a Java variable is determined by the context in which the
> variable is declared. Thus a java [sic] variable can have one of the three
> scopes at any given point in time.
> 1. Instance : - These are typical object level variables, they are
> initialized to default values at the time of creation of object, and
> remain accessible as long as the object accessible [sic].
> 2. Local : - These are the variables that are defined within a method.
> They remain accessbile only during the course of method excecution.
> When the method finishes execution, these variables fall out of scope.
> 3. Static: - These are the class level variables. They are initialized
> when the class is loaded in JVM for the first time and remain there as

That is not true.  They are not initialized when the class is loaded, but later.

Check your facts.  It's in the JLS (Java Language Specification).

> long as the class remains loaded. They are not tied to any particular
> object instance.

It's a good start, but incomplete and not entirely accurate.  Check your facts and try again.

markspace gave you a link to a (correct) tutorial and mentioned a couple of things you omitted.  

Yay, Brenden.  He's a good programmer.

-- 
Lew

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

What are the different scopes for Java variables? Software Engineer <betsy_gate@yahoo.com> - 2011-07-31 19:18 -0700
  Re: What are the different scopes for Java variables? markspace <-@.> - 2011-07-31 20:15 -0700
  Re: What are the different scopes for Java variables? Lew <lewbloch@gmail.com> - 2011-08-02 00:01 -0700

csiph-web