Ask Question

Polymorphism occurs when subclasses override the behavior from the superclass. structure TRUE FALSE

+4
Answers (1)
  1. 10 January, 20:18
    0
    The correct answer for the given question is true.

    Explanation:

    When a subclass override the method from superclass then this is known as Method overriding.

    Method override is an Runtime polymorphism.

    In the method overriding both superclass and subclass method are identical having same name and same parameter.

    Example

    class abc

    {

    void sum ()

    {

    System. out. println ("class abc "); }

    }

    class abc1 extends abc

    {

    void sum () / / override the method sum

    {

    System. out. println ("class abc1");

    }

    public static void main (String args[]) / / main method

    {

    abc ob = new abc1 (); //upcasting

    ob. sum (); / / calling function sum ()

    }

    }

    Output

    class abc1

    In this both class abc and abc1 have same method i. e sum after that we create reference variable in main method of class ob which refers the subclass object and using this reference variable it call the method sum.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Polymorphism occurs when subclasses override the behavior from the superclass. structure TRUE FALSE ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers