Hi ppl, Thanx for the replies to my first posting on Stringbuffers. This time I have one more trivia. SUN says U can over-ride a concrete method by an abstract method. Y in this World I wud do that? Need some pragmatic examples.
You might find this technique useful when you have multiple levels of inheritance. Let's say we've got an inheritance structure relating to animals. Let's start with the Animal class:
Now, let's say that we want to have a couple classes that depict a couple types of dogs. Well, obviously, many dogs have a handful of things in common, including the ability to fetch a stick. Therefore, we wouldn't want to duplicate that code in every class. So, let's define an abstract class to encapsulate the common features:
There are a couple things you should notice about this class. First of all, it contains a concrete method, fetchStick(), which allows all Dogs to share that ability. However, perhaps every Dog sleeps a little differently (it's a bit contrived, but it'll do) so I make that method abstract - even though it was concrete in the parent class, Animal. Now, let's finish our inheritance structure by creating a couple Dog classes:
By making the method abstract in the Dog class, we have forced the subclasses (the particular Dog classes) to implement their own, more specific, versions of that method. In this case, a Bulldog grumbles and snorts in its sleep while a Poodle whimpers in its sleep. Obviously, this is a rather contrived example, but I hope you see the technique being used here.