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(“ ...
 Public class Line: Drawing Object
 {
 public override void Draw()
 {
 Console .Write Line(“ I’m a Line.”);
 }
 }
...
Public class Square :
Drawing Object
{
 public override void Draw()
{
Console .Write Line(“ I’m a
Square.”);
}
}
Me...
 Class Main
 {
 Public static void main()
 {
 Drawing ObjdObj=newDrawingObj();
 dObj.Draw();
 DrawingObject li=new ...
An abstract class can
implement methods
An abstract class can
contain fields
An abstract class can
contain constructors...
An abstract class
cannot be inherited
from by a class .
Abstract class cannot
support multiple
inheritances
Interface c...
An interface look like a class but has no
implementation.The only things that they
contain are only signature of methods e...
An Abstract class has no implementation like
interface . Implementation of methods can be
use by the child class
ABSTRACT ...
of 9

Polymorphism (2)

Polymorphism Inheritance Abstract Interface
Published on: Mar 4, 2016
Published in: Career      
Source: www.slideshare.net


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

Related Documents