SlideShare uma empresa Scribd logo
1 de 17
POLYMORPHISM
          Concept & Application




         Prepared By:-
         Rakhi Kumari
         Kumar Gaurav
Polymorphism: Literal meaning
• polymorphism in Latin word which made up of
  'poly' means many and 'morphs' means forms.

• From the Greek:
  – Polus + Morphe = Polumorphos
    (many ) (shape/form)


• This is something similar to a word having several
  different meanings depending on the context
A simple word ‘Cut’ can have different meaning
depending where it is used
Polymorphism, In Context Of OOP
• Polymorphism is about an objects ability to
  provide context when methods or operators
  are called on the object.
• In OOP, Polymorphism is the characteristic of
  being able to assign a different meaning to a
  particular symbol or "operator" in different
  contexts - specifically, to allow an entity such
  as a variable, a function, or an object to have
  more than one form.
Polymorphism
• When a program invokes a method through a
  superclass variable,
  – the correct subclass version of the method is
    called,
  – based on the type of the reference stored in the
    superclass variable
• The same method name and signature can
  cause different actions to occur,
  – depending on the type of object on which the
    method is invoked
                                                       5
Polymorphism
• Polymorphism enables programmers to deal
  in generalities and
  – let the execution-time environment handle the
    specifics.
• Programmers can command objects to behave
  in manners appropriate to those objects,
  – without knowing the types of the objects
  – (as long as the objects belong to the same
    inheritance hierarchy).

                                                    6
The Meaning of the word.
• Example: The operator + has a different
  meaning in the expression 2 + 3 (add two
  integers) than in 1.7 + 3.3 (add two floating
  point numbers)




                                                  7
Types of polymorphism
• 1. compile time polymorphism
        ( function and operator overloading)



• 2.run time polymorphism
                  (virtual functions)
Method & Function Overloading

• Overloading a function simply means, that a
  function is not only defined its name but by its
  name and parameter types.
                                          These three
• The following functions are different in C++: are
                                         methods
  – Int area(int i, int k);                different.
  – void area( float i, float k);
  – Float area();


                                                        9
Method Overloading
using System;
                                              class maindemo
using System.Collections.Generic;               {
using System.Linq;                              static void Main(string[] args)
using System.Text;                                 {
                                                   Area a1= new Area();
                                                   a1.length=10;
                                                   a1.breadth=20;
  class Area{                                      int area1 =a1.calc(10,20);
     public double length;                         double area2= a1.calc(10.5, 20.2);
     public double breadth;                        a1.calc();
                                                   Console.WriteLine();
                                                   Console.Write("Area =" + area1);
      public int calc(int l, int b)
                                                   Console.WriteLine();
      { return (l * b); }                          Console.Write("Area =" + area2);
      public double calc(double l,double b)        Console.WriteLine();
      { return (l * b); }                          }
      public void calc()                        }
      { Console.Write("Area =" + 40 ); }
  }
output
Area=40;
Area=200;
Area=212.1;
Method overriding
                                             class car:vechile
using System;
                                                {
Using System.Collections.Generic;                   public override void display()
using System.Linq;                                     {
using System.Text;                                         Console.WriteLine(" It is from
                                                                          child Car");
                                                         }
                                                  }
  class vechile                                   class maindemo
  {                                         {
     public virtual void display()                static void Main(string[] args)
      {                                             {
                                                          vechile v1= new car();
         Console.WriteLine(“It is from
                                                           v1.display();
                        parent Vechile");            }
       }                                       }
  }
output
It is from child Car
Run-time polymorphism
• Run-time polymorphism, also called dynamic
  binding, or late binding is often considered as
  the object oriented feature of C#.
• Dynamic means objects are created at run
  time
• Dynamic binding offers greater flexibility and a
  higher level of abstraction than static binding
  because it is done "on the fly" when a
  program executes
Static typing & Dynamic binding

• Static typing means that the   • Dynamic binding means that
  legality of a member             the address of the code in a
  function invocation is           member function invocation
  checked at the earliest          is determined at the last
  possible moment: by the          possible moment: based on
                                   the dynamic type of the
  compiler at compile time.
                                   object at run time. It is called
  The compiler uses the static     "dynamic binding" because
  type of the pointer to           the binding to the code that
  determine whether the            actually gets called is
  member function                  accomplished dynamically
  invocation is legal.             (at run time).

                                                                 15
Static typing & Dynamic binding
• With static binding, you • Dynamic binding offers
  get better run time        greater flexibility and a
  efficiency because the     higher level of
  compiler can actually      abstraction than static
  optimize the code          binding because it is
  before running it.         done "on the fly" when
                             a program executes.
• The CLR knows how        • The CLR doesn't know
  much memory to take        how much memory to
  up for the static method   take up for the dynamic
  object                     method object
Polymorphism

Mais conteúdo relacionado

Mais procurados

Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop Kumar
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphismkiran Patel
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++Vishesh Jha
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code SmellsMario Sangiorgio
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphismlalithambiga kamaraj
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#Doncho Minkov
 
Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in JavaJava2Blog
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Paumil Patel
 

Mais procurados (20)

Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Introduction to oop
Introduction to oop Introduction to oop
Introduction to oop
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
 
Polymorphism In c++
Polymorphism In c++Polymorphism In c++
Polymorphism In c++
 
Clean code and Code Smells
Clean code and Code SmellsClean code and Code Smells
Clean code and Code Smells
 
Pointers, virtual function and polymorphism
Pointers, virtual function and polymorphismPointers, virtual function and polymorphism
Pointers, virtual function and polymorphism
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object-oriented Programming-with C#
Object-oriented Programming-with C#Object-oriented Programming-with C#
Object-oriented Programming-with C#
 
Virtual base class
Virtual base classVirtual base class
Virtual base class
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 

Destaque

Co crystalization
Co crystalizationCo crystalization
Co crystalizationSujit Kale
 
Cocrystal review 2011
Cocrystal review 2011Cocrystal review 2011
Cocrystal review 2011Simon Curtis
 
Rancidity - oxidation of oils and fats.
Rancidity - oxidation of oils and fats.Rancidity - oxidation of oils and fats.
Rancidity - oxidation of oils and fats.Mansvini Misra
 
Polymorphism and crystallisation : The mysterious phenomenon
Polymorphism and crystallisation : The mysterious phenomenonPolymorphism and crystallisation : The mysterious phenomenon
Polymorphism and crystallisation : The mysterious phenomenonMadhulika Harde
 
Fatty acids
Fatty acidsFatty acids
Fatty acidssjobli74
 
How to Manufacture Oils, Fats and Its Derivatives
 How to Manufacture Oils, Fats and Its Derivatives How to Manufacture Oils, Fats and Its Derivatives
How to Manufacture Oils, Fats and Its DerivativesAjjay Kumar Gupta
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism023henil
 

Destaque (11)

Co crystalization
Co crystalizationCo crystalization
Co crystalization
 
Cocrystal review 2011
Cocrystal review 2011Cocrystal review 2011
Cocrystal review 2011
 
Rancidity - oxidation of oils and fats.
Rancidity - oxidation of oils and fats.Rancidity - oxidation of oils and fats.
Rancidity - oxidation of oils and fats.
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Rancidity
RancidityRancidity
Rancidity
 
Polymorphism and crystallisation : The mysterious phenomenon
Polymorphism and crystallisation : The mysterious phenomenonPolymorphism and crystallisation : The mysterious phenomenon
Polymorphism and crystallisation : The mysterious phenomenon
 
Fatty acids
Fatty acidsFatty acids
Fatty acids
 
How to Manufacture Oils, Fats and Its Derivatives
 How to Manufacture Oils, Fats and Its Derivatives How to Manufacture Oils, Fats and Its Derivatives
How to Manufacture Oils, Fats and Its Derivatives
 
M.PHARM_ Rupsa Ghosh
M.PHARM_ Rupsa GhoshM.PHARM_ Rupsa Ghosh
M.PHARM_ Rupsa Ghosh
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism
 
Fatty acid synthesis
Fatty acid synthesisFatty acid synthesis
Fatty acid synthesis
 

Semelhante a Polymorphism

Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17LogeekNightUkraine
 
21CSC101T best ppt ever OODP UNIT-2.pptx
21CSC101T best ppt ever OODP UNIT-2.pptx21CSC101T best ppt ever OODP UNIT-2.pptx
21CSC101T best ppt ever OODP UNIT-2.pptxAnantjain234527
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxSRamadossbiher
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxSRamadossbiher
 
Java script Techniques Part I
Java script Techniques Part IJava script Techniques Part I
Java script Techniques Part ILuis Atencio
 
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Theo Jungeblut
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Theo Jungeblut
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismCHAITALIUKE1
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#Rainer Stropek
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & TemplatesMeghaj Mallick
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++Joan Puig Sanz
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxSurajgroupsvideo
 

Semelhante a Polymorphism (20)

C# Unit 2 notes
C# Unit 2 notesC# Unit 2 notes
C# Unit 2 notes
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
Vladymyr Bahrii Understanding polymorphism in C++ 16.11.17
 
21CSC101T best ppt ever OODP UNIT-2.pptx
21CSC101T best ppt ever OODP UNIT-2.pptx21CSC101T best ppt ever OODP UNIT-2.pptx
21CSC101T best ppt ever OODP UNIT-2.pptx
 
C by balaguruswami - e.balagurusamy
C   by balaguruswami - e.balagurusamyC   by balaguruswami - e.balagurusamy
C by balaguruswami - e.balagurusamy
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 
Java script Techniques Part I
Java script Techniques Part IJava script Techniques Part I
Java script Techniques Part I
 
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
 
Polymorphismupload
PolymorphismuploadPolymorphismupload
Polymorphismupload
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
 
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
 
Comparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphismComparison between runtime polymorphism and compile time polymorphism
Comparison between runtime polymorphism and compile time polymorphism
 
C# for Java Developers
C# for Java DevelopersC# for Java Developers
C# for Java Developers
 
P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#P/Invoke - Interoperability of C++ and C#
P/Invoke - Interoperability of C++ and C#
 
Polymorphism & Templates
Polymorphism & TemplatesPolymorphism & Templates
Polymorphism & Templates
 
Cross Platform App Development with C++
Cross Platform App Development with C++Cross Platform App Development with C++
Cross Platform App Development with C++
 
EEE 3rd year oops cat 3 ans
EEE 3rd year  oops cat 3  ansEEE 3rd year  oops cat 3  ans
EEE 3rd year oops cat 3 ans
 
CAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptxCAP444-Unit-3-Polymorphism.pptx
CAP444-Unit-3-Polymorphism.pptx
 

Mais de Kumar Gaurav

Mais de Kumar Gaurav (6)

Numerical method
Numerical methodNumerical method
Numerical method
 
Cellular network History
Cellular network HistoryCellular network History
Cellular network History
 
Cellular networks
Cellular networksCellular networks
Cellular networks
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
J2ME
J2MEJ2ME
J2ME
 
Python
PythonPython
Python
 

Último

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Último (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Polymorphism

  • 1. POLYMORPHISM Concept & Application Prepared By:- Rakhi Kumari Kumar Gaurav
  • 2. Polymorphism: Literal meaning • polymorphism in Latin word which made up of 'poly' means many and 'morphs' means forms. • From the Greek: – Polus + Morphe = Polumorphos (many ) (shape/form) • This is something similar to a word having several different meanings depending on the context
  • 3. A simple word ‘Cut’ can have different meaning depending where it is used
  • 4. Polymorphism, In Context Of OOP • Polymorphism is about an objects ability to provide context when methods or operators are called on the object. • In OOP, Polymorphism is the characteristic of being able to assign a different meaning to a particular symbol or "operator" in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.
  • 5. Polymorphism • When a program invokes a method through a superclass variable, – the correct subclass version of the method is called, – based on the type of the reference stored in the superclass variable • The same method name and signature can cause different actions to occur, – depending on the type of object on which the method is invoked 5
  • 6. Polymorphism • Polymorphism enables programmers to deal in generalities and – let the execution-time environment handle the specifics. • Programmers can command objects to behave in manners appropriate to those objects, – without knowing the types of the objects – (as long as the objects belong to the same inheritance hierarchy). 6
  • 7. The Meaning of the word. • Example: The operator + has a different meaning in the expression 2 + 3 (add two integers) than in 1.7 + 3.3 (add two floating point numbers) 7
  • 8. Types of polymorphism • 1. compile time polymorphism ( function and operator overloading) • 2.run time polymorphism (virtual functions)
  • 9. Method & Function Overloading • Overloading a function simply means, that a function is not only defined its name but by its name and parameter types. These three • The following functions are different in C++: are methods – Int area(int i, int k); different. – void area( float i, float k); – Float area(); 9
  • 10. Method Overloading using System; class maindemo using System.Collections.Generic; { using System.Linq; static void Main(string[] args) using System.Text; { Area a1= new Area(); a1.length=10; a1.breadth=20; class Area{ int area1 =a1.calc(10,20); public double length; double area2= a1.calc(10.5, 20.2); public double breadth; a1.calc(); Console.WriteLine(); Console.Write("Area =" + area1); public int calc(int l, int b) Console.WriteLine(); { return (l * b); } Console.Write("Area =" + area2); public double calc(double l,double b) Console.WriteLine(); { return (l * b); } } public void calc() } { Console.Write("Area =" + 40 ); } }
  • 12. Method overriding class car:vechile using System; { Using System.Collections.Generic; public override void display() using System.Linq; { using System.Text; Console.WriteLine(" It is from child Car"); } } class vechile class maindemo { { public virtual void display() static void Main(string[] args) { { vechile v1= new car(); Console.WriteLine(“It is from v1.display(); parent Vechile"); } } } }
  • 13. output It is from child Car
  • 14. Run-time polymorphism • Run-time polymorphism, also called dynamic binding, or late binding is often considered as the object oriented feature of C#. • Dynamic means objects are created at run time • Dynamic binding offers greater flexibility and a higher level of abstraction than static binding because it is done "on the fly" when a program executes
  • 15. Static typing & Dynamic binding • Static typing means that the • Dynamic binding means that legality of a member the address of the code in a function invocation is member function invocation checked at the earliest is determined at the last possible moment: by the possible moment: based on the dynamic type of the compiler at compile time. object at run time. It is called The compiler uses the static "dynamic binding" because type of the pointer to the binding to the code that determine whether the actually gets called is member function accomplished dynamically invocation is legal. (at run time). 15
  • 16. Static typing & Dynamic binding • With static binding, you • Dynamic binding offers get better run time greater flexibility and a efficiency because the higher level of compiler can actually abstraction than static optimize the code binding because it is before running it. done "on the fly" when a program executes. • The CLR knows how • The CLR doesn't know much memory to take how much memory to up for the static method take up for the dynamic object method object