Ask Question
17 December, 12:20

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

+2
Answers (1)
  1. 17 December, 14:37
    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?
Get an answer to your question ✅ “Polymorphism occurs when subclasses override the behavior from the superclass. structure TRUE FALSE ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers