Olivier Legat wrote:Hello everyone,
I'm having a problem in printing the class names when inheriting and I'm pretty sure the solution is fairly simple.. To better explain myself, here is a sample code:
-code-
So to write the class names of Dog and Cat I am overriding the method type(). This is incorrect (well at least for what I'm trying to do it's incorrect). I want the classes Dog and Cat to inherit a method that allows them to print their type. How can I do this?
Thanks is advance
You can use the java.lang.Object#getClass() method to get at an Object's class at runtime.
If you take a look at API of
java.lang.Class, I'm sure you can come up with a way to get at the information you're after.
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.