|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Java Declaration
I m hoping someone can pseudo code the following declaration, to clear things in my head:
======================== Calendar startTime = new GregorianCalendar(); ======================== Am I right in saying the above snippet means the following: make 'startTime' an Object of the method 'GregorianCalendar' which is in the ' Calendar ' api? Thanks for all help, Santos |
|
#2
|
|||
|
|||
|
err, that seems very wrong to me.
Calendar startTime = new GregorianCalendar(); should be Calander startTime = new startTime() you cannot replace an object with a method! |
|
#3
|
|||
|
|||
|
Eh.... Yes, well, here's the answer:
There is a class called Calendar. It's an abstract class, which means you can't actually *make* a Calendar object. It has a subclass, though, called GregorianCalender. Now, GregorianCalendar is still a Calendar, ie: anything a Calendar can do a GregorianCalendar can do too. A GregorianCalendar has been extended, though, to include extra functionality. So here's what your code is saying: Make a new Calendar object, called startTime, using the GregorianCalendar class. Creating an object this way means that the Java compiler will recognize startTime as a Calendar, so if you try to call methods from the GregorianCalendar class you'll get a compiler error. You can cast startTime to a GregorianCalendar object, though, if you need those methods. A note about default constructors: Calendar startTime = new GregorianCalendar(); GregorianCalendar() is a function of the GregorianCalendar class that basically says "Make a new object". It has no arguments and has the same name as the class. It's called a default constructor, and every class has one. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Java Declaration |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|