1 comments:

  1. Overridden depends on having instance of a class .We can override static method,but we can get parent class(polymorphism is) implementation at runtime.We can't get expected results with Polymorphic technique
    Ex:
    public class A {
    public static void m1()
    {
    System.out.println("parent m1");

    }

    }

    public class B extends A{
    static int a=25;


    public static void m1(){
    System.out.println("child implementation :");
    }

    public static void main(String[] args) {
    A a1=new B();
    a1.m1();

    }

    }

    Output:
    parent m1

    If you want to achieve polymorphism ,then we get unexpected implemetation(parent class impl).If you don't want to achieve Polymorphism ,
    then you get expected output(Child class implementation).

    B a1=ew B();
    a1.m1();

    output:
    child implementation :

    ReplyDelete