Ask Question
6 November, 21:14

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

+1
Answers (1)
  1. 6 November, 22:52
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers