chapter_12_beginning_javabook

Currentdate objects are by default american style

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ial date with the methods that class CurrentDate has inherited from class Date. For example, methods increment() and decrement() modify a CurrentDate object just as they modify a Date object. CurrentDate objects are, by default, American style dates, which means that they are shown in format MM/DD/YYYY. The default print format in class CurrentDate is ’A’. If you want a CurrentDate object to be shown in the European format DD.MM.YYYY, you must create the object in the following way CurrentDate date_of_today = new CurrentDate( ’E’ ) ; The above object creation statement invokes the second constructor of class CurrentDate. There is no technical reason why CurrentDate objects are by default American dates. This book just tries to achieve some kind of "international balance". As the objects of class Date are by default shown in the European date format, objects of class CurrentDate are by default American dates. You may, of course, modify these classes to make their default settings to fit your own preferences. Two new classes are derived from class Date in programs BetterDate.java and CurrentDate.java. Figure 12-1 shows how these class derivations can be described graphically as a UML class diagram. While studying Figure 12-1, you should note that also the empty spaces in the graphical class descriptions have a meaning. A new class can be derived from an existing base class in the following basic ways • The new class has the same members as its base class, but it has one or more new kinds of constructors. (Class CurrentDate is like this.) • The new class has the same fields and methods as its base class, and it has some additional methods. (Class BetterDate is like this.) • The new class has some new fields in addition to the inherited fields and methods. (We shall study these kinds of classes later in this book, and we shall also learn that it is not always necessary to inherit all the methods of a base class.) In practice, new classes are usually formed by mixing all the above basic ways to derive new classes. Especially when new fields are added to a new class, it is usually necessary to add new methods as well. In most cases derived classes need their own kinds of constructors. When new fields are added to a derived class, the objects of the derived class consume more memory space from the heap memory than the objects of the base cl...
View Full Document

Ask a homework question - tutors are online