Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2005

Tip: Looking for answers? Try searching our database.

what is difference between Class variables and Instance variables?

Thread view: 
rahul8143@gmail.com - 14 Aug 2005 11:13 GMT
hello,
what is difference between Class variables and Instance variables?
fartymcfly - 14 Aug 2005 11:50 GMT
On Sun, 14 Aug 2005 03:13:19 -0700, rahul8143 wrote:

> hello,
>  what is difference between Class variables and Instance variables?

A class variable is visible/usable to all methods within that class.  A
instance variable is only visible/usable within the method (instance) that
it has been declared in.  Its all about variable scope my friend!

regards,

fartymcfly
Benoy - 14 Aug 2005 12:37 GMT
Class Variable in Java

In Java Variables are of many types
out of that these are two

Class Variable

As you told about class variables they can be used any where in that
class
but, as java is an object oriented so the variables can be used in
other classes by creating objects

thank you
Benoy
Roedy Green - 14 Aug 2005 22:04 GMT
>A class variable is visible/usable to all methods within that class.  A
>instance variable is only visible/usable within the method (instance) that
>it has been declared in.  Its all about variable scope my friend!

No.  You have instance variables confused with local variables.
fartymcfly - 15 Aug 2005 07:09 GMT
>>A class variable is visible/usable to all methods within that class.  A
>>instance variable is only visible/usable within the method (instance) that
>>it has been declared in.  Its all about variable scope my friend!
>
>  No.  You have instance variables confused with local variables.

I stand corrected!

fartymcfly
alan@ljubljana.agtrz.com - 14 Aug 2005 11:51 GMT
> hello,
>  what is difference between Class variables and Instance variables?

   Is this a homework question?

--
Alan Gutierrez - alan@engrm.com
   - http://engrm.com/blogometer/index.html
   - http://engrm.com/blogometer/rss.2.0.xml
Matt Humphrey - 14 Aug 2005 14:21 GMT
> hello,
> what is difference between Class variables and Instance variables?

Instance variables belong to the object instance.  They're the fields of the
object.  Class variables belong to the class as a whole--they're static
variables.  I recommend Roedy's definitions here:

http://mindprod.com/jgloss/instancevariable.html  or if you're up to it the
JLS definition here
http://java.sun.com/docs/books/jls/second_edition/html/typesValues.doc.html#28536

Cheers,
Matt Humphrey  matth@ivizNOSPAM.com  http://www.iviz.com/
Roedy Green - 14 Aug 2005 18:58 GMT
> what is difference between Class variables and Instance variables?

you could be asking such beginner questions in comp.lang.java.help.

See http://mindprod.com/gloss/instance.html
and
http://mindprod.com/jgloss/static.html
Virgil Green - 15 Aug 2005 18:49 GMT
> hello,
>  what is difference between Class variables and Instance variables?

Class variables are more broad-minded than their narrow-minded cousins,
Instance variables.

Signature

Virgil



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.