<< 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

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
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