The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
![]() |
Home ![]() ![]() |
||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||
Class Definitions and Object Types
Every time you write a class definition, you create a new Object type, with the same name as the class. Way back in Section 1.5, when we defined the class named Hello, we also created an object type named Hello. We didn't create any variables with type Hello, and we didn't use the new command to create any Hello objects, but we could have! That example may not make any sense, since there is no reason to create a Hello object, and it is not clear what it would be good for if we did. In this chapter, we will look at some examples of class definitions that create useful new Object types. Here are the most important ideas in this chapter:
Here are some syntax issues about class definitions:
With those issues out of the way, let's look at an example of a user-defined type, Time.
|
||
Home ![]() ![]() |