Objects, Objects, Objects

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,

Blog Object

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:

Blog Object 2… Or, our constructor could have parameters…

Screen Shot 2016-01-29 at 7.20.31 AM

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:

Screen Shot 2016-01-29 at 7.20.53 AMWhile 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.

Author: christina

Christina is a first-year graduate student in the master's in English literature program here at DePaul. Her bachelor's is in English, and she comes from a strong background in tutoring kids K-12. Christina loves gaming, reading, and spreadsheets.

Leave a Reply

Your email address will not be published. Required fields are marked *