A. Notes
All data fields in the "Student" class below are instance variables because when an object is created from this class, all these variables are copied to that object, thus each instance has their own variable "name", "address", ... etc(an object is an instance of the class):
class Student {
String name;
String address;
double height;
double weight;
double gpa;
int ap;
}
2. The instance variables are always associated with a specific student x or y. We have to use the object to access instance variables. For instance, x.address, y.name, without x or y, variable "address" or "name" can not be accessed.
Student x = new Student();// an object
x.name = "Tyler";
x.address = "193 Lucy Ln";
x.height = 67.5;
x.weight = 120;
x.gpa = 5.4;
x.ap = 12;
Student y = new Student();
y.name = "Allen";
...
Student[] students = new Student[300];
...
3. Similarly, methods such as getHeight(), calculateGpa() are instance methods because they have to be associated with an instance. x.getHeight() will return student x's height. Without x, getHeight() does not return anyone's height.
4. What else should be included in a class? Are all data fields and methods of a class associated with objects?
B. Watch Slides to learn about static variables and methods
C. HW
For classes of Book, Room, Car, and Table, add at least 1 static field or method, and 2 or more instance methods. Then create 2 objects, call the static and instance methods you designed.
https://replit.com/@JoyceXu1/Static#Main.java