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