

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of class variables and the use of the 'this' keyword in java programming. It explains how class variables are independent of objects and have only one instance, regardless of the number of objects created. The document also covers the scope of variables and the difference between local, instance, and class variables. It provides examples using point.java and counter.java to illustrate the concepts.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Reading - Quiz โ Monday, March 28 Last time we looked at:
A class variable is independent of the objects in the class. There is only one instance of a class variable, regardless of how many objects exist. Math.PI is a defined as a class variable (actually a constant because it's final). Let's look at a class that includes a class variable - Counter.java The methods reset(), getValue(), and click() should all be pretty familiar to you - they are instance methods. Method getHowMany() is a class method - note the keyword static The variable howMany is a class variable - again, note the keyword static. howMany gets initialized to 0, and is incremented everytime the Counter constructor is invoked. [Draw picture] Scope We've seen that variables can only be used in certain parts of a program