I was trying to write a Java class for an exercise in my class textbook. The job was to model a credit card. I figured an important characteristic of the credit card is the expiration date. At first I just created an instance variable of type String. Then I figured I would need a member isExpired(). That made me thing String was the wrong type for this variable.
Off I went to the Java API. The first Date class I found had something to do with SQL. That did not seem right. Then I found another Date class in java.util. However the docs for this class did not seem intuitive. I want to set a day, month, and year. There used to be a way to construct a Date object with such properties. But it had been deprecated to favor the number of milliseconds since some start date. How random.
Since I am a programmer, I decided to roll my own simple Date class. This was just for instructive purposes. Following good programming practices, I made the day/month/year private. I got down to writing my own comparison member. That's when I really got tested with my knowledge of what private means. I pass another Date object reference into my compareTo member. Can my member access the private instance variables of the Date passed in? It compiles fine. But it seems wrong. My gut tells me I should only be able to access private members of "this" object. Time to ask my professor about these details.
Free Laundry
-
Apparently a lot of apartment buildings have coin operated laundry machines
in the basement. And guess what? You can order a key to unlock the payment
me...
5 years ago