Tuesday 27 August 2013

How I can skip one method in a class extending Abstract Class?

How I can skip one method in a class extending Abstract Class?

I have one abstract class named Animal having around 100 methods including
swim.
Many classes such as Dog,Cat ,Lion are extending that class.
Now there is one animal Giraffe which can't swim. But it is extending
Animal abstract class.
I want that giraffe object does not have swim method.
Giraffe g = new Giraffe();
//g.swim(); // This swim should not come.
One solution is to create One more abstract class copying all the methods
except swim. But this is not a good approach.
How I can do this using Animal abstract class? Thank in advance.

No comments:

Post a Comment