Lesson 29 of 34
Polymorphism, Abstract Classes and Interfaces
11 min 35 XP
You can't create objects of an abstract class; child classes must write its abstract methods. An interface is a contract: a class that implements it must write all its methods, and a class can implement many interfaces.
Example: edit me and press Run
Press Run to see the result here.Example: edit me and press Run
Press Run to see the result here.Shape s = new Circle(...) is runtime polymorphism: the variable's type is Shape but Circle's area() runs. Overriding is runtime polymorphism; overloading is compile-time.