120 likes | 313 Views
POLIMORFISME. GALIH WASIS WICAKSONO. PREVIEW. Inheritance lets you guarantee that all classes grouped under a certain supertype have all the methods that the supertype has.
E N D
POLIMORFISME GALIH WASIS WICAKSONO
PREVIEW • Inheritance lets you guarantee that all classes grouped under a certain supertypehave all the methods that the supertype has. • When we say any Animal, we mean Animal and any class that extends from Animal. Which again means, any class that has Animal somewhere above it in the inheritance hierarchy
POLIMORFISME • Polymorphism allows you to make changes in the method definition for the derived classes and have those changes apply to the software written in the base class. • The terms polymorphism and late binding are essentially just different words for the same concept. The term polymorphism refers to the processes of assigning multiple meanings to the same method name using late binding
OVERRIDING • The arguments and return types of your overriding method must look to the outside world exactly like the overridden method in the superclass. • Rules of overriding : • Arguments must be the same, and return types must be compatible. • The method can’t be less accessible.
CONT’D • You can mark a method to indicate that it cannot be overridden with a new definition in a derived class. You do this by adding the final modifier to the method heading. • Modifier final that definition the class, indicates that the class may not be used as a base class to derive other classes
OVERLOADING • Method overloading is nothing more than having two methods with the same name but different argument lists. • Overloading lets you make multiple versions of a method, with different argument lists, for convenience to the callers. • Since an overloading method isn’t trying to fulfill the polymorphism contract defined by its superclass, overloaded methods have much more flexibility
CONT’D • Rules of overloading : • The return types can be different. • You can’t change ONLY the return type. • You can vary the access levels in any direction.