Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-10-2007, 12:43 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Variables
I am confused about the variables. Java has 3 different variables:

Instance variables
Class variables
Local variable

Local variables are declared and used in the class. But what is the difference between class and instance variables.

Thanks for your time.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-11-2007, 03:06 AM
Member
 
Join Date: Dec 2007
Posts: 7
definewebsites is on a distinguished road
Quote:
Originally Posted by mew View Post
I am confused about the variables. Java has 3 different variables:

Instance variables
Class variables
Local variable

Local variables are declared and used in the class. But what is the difference between class and instance variables.

Thanks for your time.
Hi there mew

ok, lets take this one at a time.

Local variables are variables that are initialised and used by methods of a class. Their lifetime begins when a method is called or is running, and ends when the method has finished running.

Class variables are variables that belong to the class, are declared once and shared by the entire class as a whole. These variables are not owned by a particular instance (object) of the class/

Instance variables however are owned by objects or instances of the class and makes-up the data portion of the objects. Each object (instance) of the class will have its own separate copy of the instance variables.

Hope this helps...
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 12:48 PM
mew mew is offline
Member
 
Join Date: Nov 2007
Posts: 70
mew is on a distinguished road
Thanks definewebsites for the details.
Your explanation cleared my confusions.
Cheers.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-11-2007, 01:44 PM
Member
 
Join Date: Dec 2007
Posts: 7
definewebsites is on a distinguished road
Glad I could help...

All the best...

Cheers
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
boolean variables ravian New To Java 3 12-31-2007 05:58 AM
Initialize variables before use Java Tip Java Tips 0 12-22-2007 12:22 PM
JSP - session variables Java Tip Java Tips 0 12-02-2007 10:22 PM
variables-methods Warren New To Java 1 11-28-2007 05:14 PM
Saving Variables Fish New To Java 6 06-25-2007 09:20 PM


All times are GMT +3. The time now is 05:12 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org