E
E
Enerdgazer2020-07-09 14:24:06
Java
Enerdgazer, 2020-07-09 14:24:06

Calendar cal = Calendar.getInstance(); returns GregorianCalendar, how can methods be executed in that case?

Calendar cal = Calendar.getInstance(); returns a GregorianCalendar, how then can the methods of GregorianCalendar be executed if java is looking at the methods of the reference variable and not at the referenced object?
And why use the construction Calendar cal = Calendar.getInstance(); instead of GregorianCalendar var = new GregorianCalendar() ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2020-07-09
@iLLuzor

Calendar is an abstract class. GregorianCalendar extends it.
You need to work with Calendar and not think about a specific implementation.
Depending on the locale, a type other than GregorianCalendar may be returned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question