Documente Academic
Documente Profesional
Documente Cultură
Classes and Objects (v2) An object is a “bundle” of data (variables) and code
(functions)
(“attributes”)
This is called encapsulation, meaning that an object is A class defines a new type of variable for your program
This protects our data from random changes e.g. “a car” (class) vs. “that car over there” (instance)
Classes vs. Instances The Anatomy of a Class
int maxSpeed;
int mileage;
When we create a new Car “instance”: each object instance has its own copy
maxSpeed = max;
currentSpeed = 0;
They are used to operate on instance variables
mileage = 0;
}
}
Access Modifiers General Access Guidelines
The keyword private means that a variable or method can Methods should only be public if other parts of the program
only be seen or used by methods inside the class
may need to call them; otherwise, they should be private
If we omit the access modifier, Java lets us use class and kept as internal helper methods
Object Interactions
Public Methods Public Methods
Method Method
Hidden Method
Hidden Methods