+ 1

Can we use polymorphism for a method even if the class is not extending any class

please use a code to make me understand better

22nd Apr 2018, 11:24 AM
Devansh Gupta
Devansh Gupta - avatar
3 Answers
+ 1
but can we do so for a non inheriting class /* I am talking about methods*/
22nd Apr 2018, 11:30 AM
Devansh Gupta
Devansh Gupta - avatar
+ 1
I know, but every class you create has Object as superclass, what you can do is: Object myClass = new MyClass(); Object myClass1 = new MyClass2(); System.out.println(myClass.toString()); System.out.println(myClass2.toString());
22nd Apr 2018, 11:33 AM
Jonas Schröter
Jonas Schröter - avatar
0
Look, in the Tutorial it's mentioned that this is caused by a hierarchy of classes. By the way, every class inherits from Object.
22nd Apr 2018, 11:28 AM
Jonas Schröter
Jonas Schröter - avatar