Home TechnologyProgrammingJava Subscribe to RSS

What Is The Meaning Of "B Ob=new A( )?

Answer Question

1 Answer - Sort by: Date | Rating

    You are creating an Object named 'Ob'
    'B' reference, but a 'A' Object

    It's used in Polymorphism.


    consider a classic example...
    Animal a = new Animal();    // generic Animal Eating Generically
    a.eat();

    Horse h = new Horse();      // Horse eating Hay
    h.eat();

    Animal ah = new Horse();   // Horse eating Hay. Polymorphism works! The actual object type (Horse),
    ah.eat();            //not the reference type(Animal), is used to determine which eat() is called.


    well you need to understand the concepts of Polymorphism, methos overloading and method overriding. I suggest  you take a good book and read the topic.
    use SCJP book by Kathy Sierra and Bert Bates. Its an excellent book for Fundamentals

    msg me if in doubt.
    Hope it helps...



    1 0

    Rinav  

    answered 1 year ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International