This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I don't quite understand the codes above. I mean I know what it means, but I don't know details. So comparable is an interface here. I don't really know what interface does? Just provides more methods for the class? My teacher said if interface is comparable, there must be a compareTo method --public int compareTo(Object obj) Object is a super class that contains many objects, but why we need that here? (Object obj)?
Line 23, What does this statement mean? (Lecture) is casting? what is 'other'?
Line 24, Is the 'other' here same as the above? But how does the program know which end time is other, which end time is this??
For this program, user gives input of start time and end time. For example, 9.10(means 9.10 am)-10.23(means 10:23 am).
Line 15-19, I know what toString method does, but why we need it here? Why we need to convert double Starttime and end time to string? And plus, I didn't use variable description in later classes. Thanks for helping out.
Cheryl Scodario wrote:. So comparable is an interface here. I don't really know what interface does? Just provides more methods for the class?
An interface declares what functions are required for a class to claim that it "implements Interfacename" whatever the Interface name is. In your case, you are
implements Comparable so you have to implement what the Comparable interface requires.
The interface does not tell you how to implement the functions, just that you must implement them.
How you do it is really an implementation detail, that does not have to be made public.
Cheryl Scodario wrote:
I don't quite understand the codes above.
You're asking about very important basic things:
1. The role of the Object class (and the methods every class inherits from it including toString and more importantly equals and hashCode), and
2. the purpose if multiple inheritance (and the use of interfaces to achieve it with the specific example of the Comparable interface and how it relates to sorting).
I think you should ask your teacher for a proper clarification. Present the two points I listed and ask him to expand on these topics.