Search google for "Program to an interface not an implementation" (basically upcasting is redundant as it happens implicitly but we use supertype references instead of subclass references due to programming best practices)...
You must have created the method of Calender class or any other class which are abstract using the factory methods:
The follwing doubt came to my mind while studying-
"Calender class is an abstract, we cannot create an instance of that class. But in the above code Calender class is getting instantiated. HOW ON EARTH"
What actually happens is a subclass(of Calender) instance is created and returned by getInstance() method ans is assigned to the Calender reference c. This is an example of upcasting. We are able to use the methods of calender class by this method.(Correct me if I am wrong, if it is not an example of upcasting, but just an example of assigning a subclass object to superclass reference.)
It allows to call methods of Animal not defined in Dog and
Methods overriden by Dog.
No it still calls the methods in Dog and not in Animal (except for static methods).
I think that's what he meant.. If Animal has a fart() then a new Dog() can fart(), but it's defined in Animal, not Dog. However if both Dog and Animal define fart() the implementation in Dog is executed..
Still if you do:
and Dog implements howl();
a.howl() will crash
I just finished posting on what's a definition vs. implementation..Oracle and I disagree... What are people's takes? What does it mean to "define" a method vs. "implement" it?
Doin' Java to be one of the cool kids.
I usually use Perl;