Lesson 29 of 34
Polymorphism, Abstract Classes, InterfacesPolymorphism, Abstract Classes and Interfaces
11 min 35 XP
Abstract class-லிருந்து நேரடியாக object உருவாக்க முடியாது; அதன் abstract methods-ஐ child classes எழுத வேண்டும். Interface என்பது ஒப்பந்தம்: implements செய்யும் class அதன் எல்லா methods-ஐயும் எழுத வேண்டும். ஒரு class பல interfaces-ஐ implement செய்யலாம்.
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(...) என்பது runtime polymorphism: variable-ன் type Shape, ஆனால் இயங்குவது Circle-ன் area(). Overriding = runtime, overloading = compile-time.
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.