Your SlideShare is downloading. ×
Example In C#Shows How Object Oriented            Is  Classes/PolymorphesimInherentence/Overloading       & Overriding    ...
using System;using System.Collections.Generic;using System.Text;namespace uml{    class Shape    {        public virtual v...
using System;using System.Collections.Generic;using System.Text;namespace uml{    class Rectangle:Shape    {        public...
S.draw();             //S.printCenter();      error             Circle C = new Circle();             C.printCenter();     ...
Upcoming SlideShare
Loading in...5
×

C# example (Polymorphesim)

291

Published on

Example In C#
Classes/Polymorphisem
Inherentence/Overloading
& Overriding

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
291
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "C# example (Polymorphesim)"

  1. 1. Example In C#Shows How Object Oriented Is Classes/PolymorphesimInherentence/Overloading & Overriding Done By:- MARWA SAMIH AL-AMRI
  2. 2. using System;using System.Collections.Generic;using System.Text;namespace uml{ class Shape { public virtual void draw() { Console.WriteLine("Empty"); } }{using System;using System.Collections.Generic;using System.Text;namespace uml{ class Circle:Shape { public override void draw() { Console.WriteLine("This is Circle"); } public double m (int x,int y) { return x * y; } public double m(int x, double y, int z) { Console.WriteLine("nnthe integer version = "+ m(1,2)); Console.WriteLine("the double version = " + m(2.3 , 2)); Console.WriteLine("with different order = " + m(2, 2.3)); return x * y / z; } public double m(double x, int y) { return x * y; } public double m(int x, double y) { return x / y; } }}
  3. 3. using System;using System.Collections.Generic;using System.Text;namespace uml{ class Rectangle:Shape { public override void draw() { Console.WriteLine("This is Rectangle"); } }}using System;using System.Collections.Generic;using System.Text;namespace uml{ class Square:Rectangle { public override void draw() { base.draw(); Console.WriteLine("this is Square"); } }}using System;using System.Collections.Generic;using System.Text;namespace uml{ class Program { static void Main(string[] args) { Shape S; Rectangle R = new Rectangle(); S = R; S.draw(); S = new Circle();
  4. 4. S.draw(); //S.printCenter(); error Circle C = new Circle(); C.printCenter(); S = new Square(); S.draw(); R = new Square(); S = R; S.draw(); //R = S; error Console.WriteLine("n"); Shape [] sh = new Shape[4]; sh[3] = new Shape(); sh[0] = new Rectangle(); sh[1] = new Circle(); sh[2] = new Square(); for (int i = 0; i < 4; i++) sh[i].draw(); } }}

×