SlideShare a Scribd company logo
We Can Implement Polymorphism In C #
Through Method Overloading and Method
Overriding
POLYMORPHISM
12/7/2015 1
Method Overloading & Method Overriding
 Public class Drawing Object
 {
 public void Draw()
 {
 Console .Write Line(“ I’m just
a generic drawing object.”);
 }
 }
POLYMORPHISM
Shows the drawing object class this
will be the base class for other
objects to inherit from ,It has a
single method named Draw() .the
Draw Method has a virtual Modifier
.This virtual Modifier indicates to
derived classes that they can
override this method
12/7/2015 2
 Public class Line: Drawing Object
 {
 public override void Draw()
 {
 Console .Write Line(“ I’m a Line.”);
 }
 }
 Public class Circle : Drawing Object
 {
 public override void Draw()
 {
 Console .Write Line (“ I’m a Circle .”);
METHODOVERLOADING&
METHODOVERRIDING
12/7/2015 3
Public class Square :
Drawing Object
{
 public override void Draw()
{
Console .Write Line(“ I’m a
Square.”);
}
}
Method
Overloading
& Method
Overriding
12/7/2015 4
 Class Main
 {
 Public static void main()
 {
 Drawing ObjdObj=newDrawingObj();
 dObj.Draw();
 DrawingObject li=new Line();
 Li.Draw();
 DrawingObject cr=new Circle();
 Cr.Draw();
 DrawingObject sq=newSquare();
 Sq.Draw();
 Console.ReadKey();
 }
 }
 }
Method
Overloading
& Method
Overriding
12/7/2015 5
An abstract class can
implement methods
An abstract class can
contain fields
An abstract class can
contain constructors
or destructors
An interface cannot
implement methods
An interface can
inherit from another
class
An interface can
contain signature
ABSTRACT CLASS & INTERFACE
12/7/2015 6
An abstract class
cannot be inherited
from by a class .
Abstract class cannot
support multiple
inheritances
Interface cannot
contain constructors
or destructors
Interface can
support multiple
inheritances
ABSTRACT CLASS & INTERFACE
12/7/2015 7
An interface look like a class but has no
implementation.The only things that they
contain are only signature of methods events
and or properties .the reason interface only
provide declarations is because they are
inherit by classes and which provide
implementation for each interface member
declared
INTERFACE
12/7/2015 8
An Abstract class has no implementation like
interface . Implementation of methods can be
use by the child class
ABSTRACT CLASS
12/7/2015 9

More Related Content

TXT
PPTX
On Lightweight Metamodel Extension to Support Modeling Tools Agility - ECMFA...
PDF
[Question Paper] Object Oriented Programming With C++ (Revised Course) [April...
PDF
iOS for Android Developers (with Swift)
PDF
[Question Paper] Object Oriented Programming With C++ (Revised Course) [June ...
PPTX
#OOP_D_ITS - 9th - Template
DOCX
C interview questions for experienced
PPTX
Puzles C#
On Lightweight Metamodel Extension to Support Modeling Tools Agility - ECMFA...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [April...
iOS for Android Developers (with Swift)
[Question Paper] Object Oriented Programming With C++ (Revised Course) [June ...
#OOP_D_ITS - 9th - Template
C interview questions for experienced
Puzles C#

Viewers also liked (17)

PPTX
Inheritance question class 12th
PPT
Introduction to method overloading & method overriding in java hdm
PDF
itft-Inheritance in java
PDF
Inheritance and Method Overriding
PDF
OOP Inheritance
PPTX
Multiple inheritance possible in Java
PPT
Java: Class Design Examples
PPT
Inheritance, polymorphisam, abstract classes and composition)
PPT
Oop Presentation
PDF
Chapter2 Encapsulation (Java)
PPTX
Flavor encapsulation assignment
PPTX
Object Orinted Programing(OOP) concepts \
PPTX
Inheritance in JAVA PPT
PPTX
Inheritance
PPT
20. Object-Oriented Programming Fundamental Principles
PPTX
Constructor in java
PPT
Amadeus PPT
Inheritance question class 12th
Introduction to method overloading & method overriding in java hdm
itft-Inheritance in java
Inheritance and Method Overriding
OOP Inheritance
Multiple inheritance possible in Java
Java: Class Design Examples
Inheritance, polymorphisam, abstract classes and composition)
Oop Presentation
Chapter2 Encapsulation (Java)
Flavor encapsulation assignment
Object Orinted Programing(OOP) concepts \
Inheritance in JAVA PPT
Inheritance
20. Object-Oriented Programming Fundamental Principles
Constructor in java
Amadeus PPT
Ad

Similar to Polymorphism (2) (20)

PDF
C# Starter L02-Classes and Objects
PPTX
Andrei Iacob - SOLID: Strategies for Implementing Object–Oriented Design Prin...
PPTX
Session 10 - OOP with Java - Abstract Classes and Interfaces
PPTX
Advanced programming topics asma
PPTX
abstract,final,interface (1).pptx upload
PPTX
OOP with Java - Abstract Classes and Interfaces
PPSX
OOP with Java - Abstract Classes and Interfaces
PPT
Polymorphism.pptthis is oops one of the most important feature polymorphism
PPTX
20.4 Java interfaces and abstraction
PPT
Oop lec 4(oop design, style, characteristics)
PDF
Exception handling and packages.pdf
PPTX
Interface in java
PDF
Example for Abstract Class and Interface.pdf
PPT
this is the concept in C++ under object oriented programming language "POLYMO...
PPT
Java interface
PDF
Starting Out with Java From Control Structures through Data Structures 3rd Ed...
PPTX
classes object fgfhdfgfdgfgfgfgfdoop.pptx
PPTX
inheritance, Packages and Interfaces.pptx
DOCX
Introduction to object oriented programming concepts
C# Starter L02-Classes and Objects
Andrei Iacob - SOLID: Strategies for Implementing Object–Oriented Design Prin...
Session 10 - OOP with Java - Abstract Classes and Interfaces
Advanced programming topics asma
abstract,final,interface (1).pptx upload
OOP with Java - Abstract Classes and Interfaces
OOP with Java - Abstract Classes and Interfaces
Polymorphism.pptthis is oops one of the most important feature polymorphism
20.4 Java interfaces and abstraction
Oop lec 4(oop design, style, characteristics)
Exception handling and packages.pdf
Interface in java
Example for Abstract Class and Interface.pdf
this is the concept in C++ under object oriented programming language "POLYMO...
Java interface
Starting Out with Java From Control Structures through Data Structures 3rd Ed...
classes object fgfhdfgfdgfgfgfgfdoop.pptx
inheritance, Packages and Interfaces.pptx
Introduction to object oriented programming concepts
Ad

More from Army Public School and College -Faisal (20)

PPTX
INPUT AND OUTPUT DEVICES
PPTX
INPUT AND OUTPUT DEVICES
PDF
Module 2 handouts part 2
PDF
Module 2 handouts part 1
DOCX
Cookies may be set by the website you are visiting
PPT
Boolean and comparison_instructions
PPTX
Object Oriented Programming
PPTX
Lecture 1 progrmming with C
PPT
Parallel processing Concepts

Recently uploaded (20)

PPT
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
DOC
field study for teachers graduating samplr
PPTX
Definition and Relation of Food Science( Lecture1).pptx
PDF
esg-supply-chain-webinar-nov2018hkhkkh.pdf
PPTX
A slide for students with the advantagea
PPT
APPROACH TO DEVELOPMENTALlllllllllllllllll
PPTX
Condensed_Food_Science_Lecture1_Precised.pptx
PPTX
The-Scope-of-Food-Quality-and-Safety.pptx managemement
PPTX
Prokaryotes v Eukaryotes PowerPoint.pptx
PPT
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
PDF
Understanding the Rhetorical Situation Presentation in Blue Orange Muted Il_2...
PPTX
DPT-MAY24.pptx for review and ucploading
PDF
iTop VPN Crack Latest Version 2025 Free Download With Keygen
PPTX
Your Guide to a Winning Interview Aug 2025.
PPT
2- CELL INJURY L1 Medical (2) gggggggggg
PPT
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
PPTX
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
PDF
Parts of Speech Quiz Presentation in Orange Blue Illustrative Style.pdf.pdf
PPTX
1751884730-Visual Basic -Unitj CS B.pptx
PPTX
Overview Planner of Soft Skills in a single ppt
Gsisgdkddkvdgjsjdvdbdbdbdghjkhgcvvkkfcxxfg
field study for teachers graduating samplr
Definition and Relation of Food Science( Lecture1).pptx
esg-supply-chain-webinar-nov2018hkhkkh.pdf
A slide for students with the advantagea
APPROACH TO DEVELOPMENTALlllllllllllllllll
Condensed_Food_Science_Lecture1_Precised.pptx
The-Scope-of-Food-Quality-and-Safety.pptx managemement
Prokaryotes v Eukaryotes PowerPoint.pptx
notes_Lecture2 23l3j2 dfjl dfdlkj d 2.ppt
Understanding the Rhetorical Situation Presentation in Blue Orange Muted Il_2...
DPT-MAY24.pptx for review and ucploading
iTop VPN Crack Latest Version 2025 Free Download With Keygen
Your Guide to a Winning Interview Aug 2025.
2- CELL INJURY L1 Medical (2) gggggggggg
NO000387 (1).pptsbsnsnsnsnsnsnsmsnnsnsnsjsnnsnsnsnnsnnansnwjwnshshshs
cse couse aefrfrqewrbqwrgbqgvq2w3vqbvq23rbgw3rnw345
Parts of Speech Quiz Presentation in Orange Blue Illustrative Style.pdf.pdf
1751884730-Visual Basic -Unitj CS B.pptx
Overview Planner of Soft Skills in a single ppt

Polymorphism (2)

  • 1. We Can Implement Polymorphism In C # Through Method Overloading and Method Overriding POLYMORPHISM 12/7/2015 1
  • 2. Method Overloading & Method Overriding  Public class Drawing Object  {  public void Draw()  {  Console .Write Line(“ I’m just a generic drawing object.”);  }  } POLYMORPHISM Shows the drawing object class this will be the base class for other objects to inherit from ,It has a single method named Draw() .the Draw Method has a virtual Modifier .This virtual Modifier indicates to derived classes that they can override this method 12/7/2015 2
  • 3.  Public class Line: Drawing Object  {  public override void Draw()  {  Console .Write Line(“ I’m a Line.”);  }  }  Public class Circle : Drawing Object  {  public override void Draw()  {  Console .Write Line (“ I’m a Circle .”); METHODOVERLOADING& METHODOVERRIDING 12/7/2015 3
  • 4. Public class Square : Drawing Object {  public override void Draw() { Console .Write Line(“ I’m a Square.”); } } Method Overloading & Method Overriding 12/7/2015 4
  • 5.  Class Main  {  Public static void main()  {  Drawing ObjdObj=newDrawingObj();  dObj.Draw();  DrawingObject li=new Line();  Li.Draw();  DrawingObject cr=new Circle();  Cr.Draw();  DrawingObject sq=newSquare();  Sq.Draw();  Console.ReadKey();  }  }  } Method Overloading & Method Overriding 12/7/2015 5
  • 6. An abstract class can implement methods An abstract class can contain fields An abstract class can contain constructors or destructors An interface cannot implement methods An interface can inherit from another class An interface can contain signature ABSTRACT CLASS & INTERFACE 12/7/2015 6
  • 7. An abstract class cannot be inherited from by a class . Abstract class cannot support multiple inheritances Interface cannot contain constructors or destructors Interface can support multiple inheritances ABSTRACT CLASS & INTERFACE 12/7/2015 7
  • 8. An interface look like a class but has no implementation.The only things that they contain are only signature of methods events and or properties .the reason interface only provide declarations is because they are inherit by classes and which provide implementation for each interface member declared INTERFACE 12/7/2015 8
  • 9. An Abstract class has no implementation like interface . Implementation of methods can be use by the child class ABSTRACT CLASS 12/7/2015 9