- Discuss the JimsCar.java and DriveJimsCar.java
programs in this directory.
- A "class" defines the behavior of an "object."
- One class can describe many "instances" (objects)
which are members of that class, and share many of same
general properties.
- Example:
String firstString = "The sun is shining.";
String secondString = "The moon is full.";
- firstString and secondString are instances
of the class String.
- We can invoke a method on an object to change it
or get some information from it or ask it to do
something. For example,
int howLong = firstString.length();
would put the value 20 (the number of characters
in "The sun is shining.") into the
variable "howLong".
- Each Java class has methods which describe what it
can do. For the String class,
the documentation from Sun is
here, for example.
- Some methods can be run on the class iself,
while others can only be invoked with an instance.
Example:
double x = Math.abs(-3); // Here "Math" is the class itself.
int y = firstString.length(); // While here "firstString" is an instance of the String class.
- These notions will probably take some practice
and exposure before they make a whole lot of sense.
Stay tuned; this is just the first pass.