Determining which method shows polymorphism

  • Thread starter Thread starter friendbobbiny
  • Start date Start date
  • Tags Tags
    Method
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 1K views
friendbobbiny
Messages
49
Reaction score
2

Homework Statement

Which of them is an example of polymorphism?
Code:
public Class D extends B
{

public void f()
{
    this.g(); // 1
}

public void g()
{
    super.g(); // 2
}}

Homework Equations



Polymorphism: The ability of an object to refer to objects of other types. The ability of a method to have different functionalities, depending on the class type invoking it.

The Attempt at a Solution



This was what I understood to be my teacher's logic:

Imagine a class E that extends B
The class also rewrites method g().

Code:
public static void main(String[]args)
{

E e = new E ();
D d = new D ();

e.f(); // calls the overriden g() method in E
d.f(); // cals the g() method in D, which calls the g() method in B}
I can understand why method f() shows polymorphism via this example. How is method g() not an
instance of polymorphism though?
 
Last edited:
Physics news on Phys.org