Polymorph Is M

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

I.

Objectives
At the end of the lesson the students are expected to:
a. Know what is Polymorphism
b. Use polymorphism at a simple level through inheritance to enable easy code extension
c. Appreciate what is the ability of polymorphism.
B. Motivation

What is your style of courting a girl?


What is your style in studying?
Activity
Volume computation
Steps:
1. Compute the volume of:
Rectangle1(length=3, width=5, height=4)
Rectangle2(length=2, width=6, height=3)
2. Formula=lxwxh
3.What have you realized based on our activity?
Polymorphism is the ability to define multiple
classes that can be used interchangeably, while
allowing each class to utilize the same properties or
methods in various ways.
Polymorphism allows the usage of objects with
the same names, regardless of what type of object
is in use at the moment.

For example, given a base of “ Shape,”


polymorphism enables the programmer to define
the different “CalculateArea,” method of the
derived classes in the same way, no matter what
type of “Shape” object is being used at the time .
Most OOP systems provide polymorphism
through inheritance. The main procedure in the
following example demonstrates inheritance-
based polymorphism.
A. Application
Assessment

Write True or False


___1. Most OOP systems provide polymorphism through inheritance
___2. Polymorphism is the ability to define multiple classes that can
be used interchangeably, while

allowing each class to utilize the same properties or methods in


various ways.
___3. Polymorphism is different method, the same result.

___4. Interfaces provide another way you can accomplish


polymorphism in Java.
___5. Polymorphism is one of the principle of OOP.
Family Tree
Steps:
1. Set 1 whole sheet of pad paper
2. Make a family tree/binary tree diagram
3. Presentation of output is chosen randomly
Inheritance is a way to reuse code of existing objects, or to establish a subtype from an
existing object, or both, depending upon programming language support. In classical
inheritance where objects are defined by classes, classes can inherit attributes and behavior
from pre-existing classes called base classes, superclasses, parent classes or ancestor classes.
The resulting classes are known as derived classes, subclasses or child classes. The
relationships of classes through inheritance gives rise to a hierarchy.
Subclasses and Superclasses A subclass is a modular, derivative class that inherits one or more
properties from another class (called the superclass). The properties commonly include class
data variables, properties, and methods or functions. The superclass establishes a common
interface and foundational functionality, which specialized subclasses can inherit, modify, and
supplement. The software inherited by a subclass is considered reused in the subclass. In some
cases, a subclass may customize or redefine a method inherited from the superclass. A
superclass method which can be redefined in this way is called a virtual method.
One of the most important non-linear information structure
___2. a way to reuse code of existing objects
___3. A superclass method which can be redefined in this way is called a___
___4. is a modular, derivative class that inherits one or more properties from another
Class.
___5. The relationships of classes through inheritance gives rise to a
Assignment
Make a hierarchy/inheritance diagram in any field.

You might also like