When you create a class definition, you make an object type of the same name. An object is basically a reference to a block that has data and methods concerning that data. First, you want to create instance variables. These tell the user, “what kind of attributes does this object have?” For instance,
Above, when we think of time, we think of what defines time. Well, that’s easy! Hours, minutes, and seconds. These are your instance variables. Now, we can take it a step further when we need to initialize these variables and give them purpose using a constructor:
The first gives a general outlook on time whereas the second is a little more involved and gives you a bit more control over your time methods… Oh! Speaking of methods:
While these technically aren’t methods within the class.. they are methods used with a newly created time object. We could have added methods within the class such as “removeAnHour()” that would take whatever time value you passed to it and set it back one hour. When playing with objects in Java, I recommend drawing them out and seeing how they’re set up so that you may easily visualize what’s happening.