136k views
0 votes
Polymorphism occurs when subclasses override the behavior from the superclass. structure TRUE FALSE

User Dariah
by
5.9k points

1 Answer

0 votes

Answer:

The correct answer for the given question is true.

Step-by-step 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.

User Nobik
by
5.8k points