Concept of overridding in java
<p>A method in superclass works for all the subclasses in java....If a subclass has its own independent method, how can i make it work...</p>

<pre><code>class  Polymorphism3 {

 public static void main(String[] args) {
            // note how these are all considered objects of type Animal by Java
            Animal[] a = new Animal[4];
            a[0] = new Mouse();
            a[1] = new Bird();
            a[2] = new Horse();
            a[3] = new Animal();            
            for (int i=0;i&lt;4;i++) {
                a[i].pullTail();                
            }           

//...       


class Animal {
    public void pullTail() {
        System.out.println("I don't know what to say.");
    }
}

class Mouse extends Animal {
    public void pullTail() {
        System.out.println("fart");
    }
}

class Bird extends Animal {
    public void pullTail() {
        System.out.println("tweet");
    }

    public void fly() {
        System.out.println("flap");
    }
}

class Horse extends Animal {
    public void pullTail() {
        System.out.println("neigh");
    }
}
</code></pre>
