<< Chapter < Page Chapter >> Page >

Some methods are overloaded

The two methods named Equals are defined as overloaded methods in the Object class. (They have the same name and different formal argument lists.)

Some methods are meant to be overridden

Some of these methods are intended to be overridden for various purposes. This includes GetHashCode , and ToString .

Some methods are meant to be used as is

However, some of the methods, such as GetType are intended to be used as is without overriding.

Three distinct forms of polymorphism

From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in C#:

  • Method overloading
  • Method overriding through class inheritance
  • Method overriding through interface inheritance

Method overloading

I will begin the discussion of polymorphism with method overloading, which is the simplest of the three. I will cover method overloading in this module andwill cover polymorphism based on overridden methods using class inheritance and interface inheritance in future modules.

Duplicate method names

C# allows you to have two or more method definitions in the same scope with the same name, provided that they have different formal argument lists. This ismethod overloading .

Compile-time polymorphism

Some authors refer to method overloading as a form of compile-time polymorphism , as distinguished from run-time polymorphism . This distinction comes from the fact that, for each method call, the compiler determines whichmethod (from a group of overloaded methods) will be executed. This decision is made when the program is compiled.

In contrast, with method overriding, the determination of which overridden method to execute isn't made until runtime.

Selection based on the argument list

In practice, with overloaded methods, the compiler simply examines the types, number, and order of the parameters being passed in a method call and selectsthe overloaded method having a matching formal argument list.

Preview

Keeping it short and simple

In these modules on polymorphism, I will explain sample programs that are as short and as simple as I know howto make them, while still illustrating the important points regarding polymorphism. My objective is to make the polymorphicconcepts as clear as possible without having those concepts clouded by other programming issues.

Because of their simplicity, these programs aren't likely to resemble problems that you will encounter in the real world. I will simply ask you totrust me when I tell you that polymorphism has enormous application in real world programming.

A sample program

I will explain a sample program named Polymorph01 to illustrate method overloading. A complete listing of the program is provided in Listing 4 near the end of the module.

Within the class and the hierarchy

Method overloading can occur both within a class definition, and vertically within the class inheritance hierarchy.

In other words, an overloaded method can be inherited into a class that defines other overloaded versions of the method.

The program named Polymorph01 illustrates both aspects of method overloading.

Questions & Answers

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Xna game studio. OpenStax CNX. Feb 28, 2014 Download for free at https://legacy.cnx.org/content/col11634/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Xna game studio' conversation and receive update notifications?

Ask