friendbobbiny
- 49
- 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}
instance of polymorphism though?
Last edited: