This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java (beginner) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java (beginner)" Watch "java (beginner)" New topic
Author

java (beginner)

PadmajaSudhir
Greenhorn

Joined: Feb 28, 2001
Posts: 1
what is a class variable and Instance variable ?
Fawad Khan
Ranch Hand

Joined: Feb 13, 2001
Posts: 36
Hi Sudhir,
Look, every variable is different from other on the basis of its scope and access. Instance and class variables are the same. See,
class XYZ{
// Variables declared here (after class braces and not in any // method braces) are called instance or class variables.
myMethod(){
// Variables declared here ( in the braces of a //method) are known // as local( to the method //where they are ) variables .
}
}


Seeking Certification
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
There is a little more to it than that Fawad. Class level variables are static, meaning that if there are 20 instances of a class, they all share that variable. So if object A changes a class variable to 20, then it will be 20 when you reference it from object B as well.
Instance variables belong to an instance of a class. Every object holds it own value. So if object A changes its instance variable to 20, object B will not have its instance variable changed also.
The third type is local variables, and those are variables that are inside of methods.
Bill
Helmut Lerch
Ranch Hand

Joined: Feb 11, 2001
Posts: 48
Originally posted by PadmajaSudhir:
what is a class variable and Instance variable ?

Perhaps you take a look at http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java (beginner)
 
Similar Threads
regard on k&b book
Home loans in India - fixed or floating ?
WA #1.....word association
Running two threads
Dont declare global variables in Servlet