hey guys iam working in a maintenace project this is the first time iam using Calender.when i saw the api of java.util.Calender i found that it is an abstract class and i have seen a statement in a java class
Calendar rightNow = Calendar.getInstance();
how can this getInstance() method can return a calender object since abstact class cannot be instantiated
however java.util.Calender is not extended by any java class in my project they have imported this statement
This line does not mean that the getInstance method returns a Calendar object. It means that it return an object whose type extends the Calendar class. More generally,means that classMethod returns an object that is a ReferenceType object (if ReferenceType is a concrete class), returns a object that is a subclass of ReferenceType (if ReferenceType is concrete or abstract), or returns an object that implements ReferenceType (if ReferenceType is an interface).
If you add the lineafter that line, it will tell you what the class of the returned object actually is.
Calendar itself is abstract, but the static method returns an instance of a non-abstract subclass of Calendar.
In the case of Calendar, the returned calendar is either a sun.util.BuddhistCalendar (this is a Sun internal class), a java.util.GregorianCalendar or (in Java 6 and up) a java.util.JapaneseImperialCalendar (which is package private). In the case of Toolkit, this is some internal class.
What you need to remember from all of this is: the method returns some unknown subclass, and the only thing you are sure of is that it is a Calendar / Toolkit / DateFormat / etc. You should never count on the specific subclass (like GregorianCalendar), since it may change in the future.
Its kindly requested to both raghu ram and amir please make sure your spelling is correct. First for both raghu ram and amir - its not Calender class, its Calendar class. And secondly, for raghu ram - its not refference its simply reference. YOUR correct spelling will make the job of others way easier. Thank you.....
.....For Every Problem There Is a Solution.....