Inheritance/Single

From Rosetta Code
Revision as of 15:57, 27 April 2008 by rosettacode>Mwn3d (Created task with Java)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Inheritance/Single
You are encouraged to solve this task according to the task description, using any language you may know.

Show a tree of classes which inherit from each other. The top of the tree should be a class called Animal. The second level should have Dog and Cat. Under Dog should be Lab and Collie. None of the classes need to have any functions, the only thing they need to do is inherit from the specified superclasses (overriding functions should be shown in Polymorphism). The tree should look like this:

            Animal
              /\
             /  \
            /    \
           Dog   Cat
           /\
          /  \
         /    \
        Lab   Collie

Java

<java>public class Animal{

  //functions go here...

}</java> <java>public class Dog extends Animal{

  //functions go here...

}</java> <java>public class Cat extends Animal{

  //functions go here...

}</java> <java>public class Lab extends Dog{

  //functions go here...

}</java> <java>public class Collie extends Dog{

  //functions go here...

}</java>