Chapter two was all about objects and classes and how they relate and interact. I found this to be a very helpful refresher on how java works and used OOP (Object Oriented Programming). I am beginning to remember how to read and write java. Because classes are like a blueprint of how an object will function, it is not hard to make one class and several objects. This allows for adding more things to a program without changing previously edited code. Objects have their own variables and methods that are either global variables and methods, inherited variables and methods from its class, or local variables and methods. A super class can be created so many classes can inherit traits from the larger class. I was able to complete the "Be the Compiler" page in Chapter 2 with relative ease.

The errors were relatively easy to spot. In the "A" section, the "t" variable was never defined. It would appear that the programmer would have wanted to declare "t" as a "new TapeDeck". To do this, they would have had to type TapeDeck t = new TapeDeck();" in the "TapeDeckTestDrive" class.
The error in the "B" section was also simple. The "playDVD" function that was called in the "DVDPlayerTestDrive" class was not defined. In order to do this the programmer would need to type "void playDVD() { //some code to run }" in the "DVDPlayer" class. this way the code in the "DVDPlayerTestDrive" class would call the "playDVD" fuction of the "new DVDPlayer" as defined by "d" from the "DVDPlayer" class.
No comments:
Post a Comment