I'm a new programmer in JAVA. And i need to understand the "interfaces" with (real examples).
Let me to explain it:
This is an abstract class for polymorphism for the Animals (Dogs, Cats etc...):
This is an interface just for them (Tame) Animals.
I need to implements the Tame interface to the "Dog". As you know dog is a tame animal.
I have another class is for the Lion. Lion is not a Lame.
My problem is:
I can't access to the "Dog" (interface) via the polymorphism with this code:
IS NOT WORKING!! But i can't access to it via the interface:
* Why i can't access to the "play" method via Animal? * We know the interface is 100% abstract. If so why i can create a conrete class of it? Thanks a lot
In this code you are trying to call the play method from an animal, which does not have access to the play() method. As mentioned before, even though you know it is a dog, and everyone else that reads the code knows it is a dog, to the system it is just an animal.
You could switch your array to something like Dog anm = new Dog, which would allow you to access play().
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."