SlideShare una empresa de Scribd logo
1 de 4
Example In C#
Shows How Object Oriented
            Is


  Classes/Polymorphesim
Inherentence/Overloading
       & Overriding




       Done By:-
  MARWA SAMIH AL-AMRI
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;
        }



    }
}
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();
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();

        }
    }
}

Más contenido relacionado

La actualidad más candente (20)

Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Day 2 examples u2f13
Day 2 examples u2f13Day 2 examples u2f13
Day 2 examples u2f13
 
Day 9 examples u1w14
Day 9 examples u1w14Day 9 examples u1w14
Day 9 examples u1w14
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
week-11x
week-11xweek-11x
week-11x
 
Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2Bcsl 033 data and file structures lab s3-2
Bcsl 033 data and file structures lab s3-2
 
Implement a queue using two stacks.
Implement a queue using two stacks.Implement a queue using two stacks.
Implement a queue using two stacks.
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
week-4x
week-4xweek-4x
week-4x
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Javascript Array map method
Javascript Array map methodJavascript Array map method
Javascript Array map method
 
6. binary tree
6. binary tree6. binary tree
6. binary tree
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
C programs
C programsC programs
C programs
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
2.5 function transformations
2.5 function transformations2.5 function transformations
2.5 function transformations
 
2.6 transformations
2.6 transformations2.6 transformations
2.6 transformations
 
5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment 5. Destructuring | ES6 | Assignment
5. Destructuring | ES6 | Assignment
 

Destacado

SRS Document Of Course management software system.doc
SRS Document Of Course management software system.docSRS Document Of Course management software system.doc
SRS Document Of Course management software system.docMaRwa Samih AL-Amri
 
100 PHP question and answer
100 PHP  question and answer100 PHP  question and answer
100 PHP question and answerSandip Murari
 
Classes and Objects In C# With Example
Classes and Objects In C# With ExampleClasses and Objects In C# With Example
Classes and Objects In C# With ExampleCheezy Code
 
C# and Dot Net by Example
C# and Dot Net by ExampleC# and Dot Net by Example
C# and Dot Net by ExampleGanesh Karthik
 
Beer vs wine by Sandip Murari
Beer vs wine by Sandip MurariBeer vs wine by Sandip Murari
Beer vs wine by Sandip MurariSandip Murari
 
Modern Management Thoughts
Modern Management ThoughtsModern Management Thoughts
Modern Management ThoughtsRavi Yasas
 
Proposal: A Study on Business Communucation System of KAZ Software
Proposal: A Study on Business Communucation System of KAZ SoftwareProposal: A Study on Business Communucation System of KAZ Software
Proposal: A Study on Business Communucation System of KAZ SoftwareMinhas Kamal
 
Software Project Management: Release Notes
Software Project Management: Release NotesSoftware Project Management: Release Notes
Software Project Management: Release NotesMinhas Kamal
 
Software Project Management: Configuration Management
Software Project Management: Configuration ManagementSoftware Project Management: Configuration Management
Software Project Management: Configuration ManagementMinhas Kamal
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
Software Requirements Specification on Bengali Braille to Text Translator
Software Requirements Specification on Bengali Braille to Text TranslatorSoftware Requirements Specification on Bengali Braille to Text Translator
Software Requirements Specification on Bengali Braille to Text TranslatorMinhas Kamal
 
Software Project Management: Testing Document
Software Project Management: Testing DocumentSoftware Project Management: Testing Document
Software Project Management: Testing DocumentMinhas Kamal
 
A pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesA pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesGraham Bleakley
 
Project Proposal: Bengali Braille to Text Translation
Project Proposal: Bengali Braille to Text TranslationProject Proposal: Bengali Braille to Text Translation
Project Proposal: Bengali Braille to Text TranslationMinhas Kamal
 
Software Project Management: Project Planning
Software Project Management: Project PlanningSoftware Project Management: Project Planning
Software Project Management: Project PlanningMinhas Kamal
 
Software Project Management: Change Control
Software Project Management: Change ControlSoftware Project Management: Change Control
Software Project Management: Change ControlMinhas Kamal
 

Destacado (20)

Oracle qs
Oracle qsOracle qs
Oracle qs
 
example of OMT TECHNIQUE (UML)
example of OMT TECHNIQUE (UML)example of OMT TECHNIQUE (UML)
example of OMT TECHNIQUE (UML)
 
SRS Document Of Course management software system.doc
SRS Document Of Course management software system.docSRS Document Of Course management software system.doc
SRS Document Of Course management software system.doc
 
Oracle examples
Oracle examplesOracle examples
Oracle examples
 
100 PHP question and answer
100 PHP  question and answer100 PHP  question and answer
100 PHP question and answer
 
Classes and Objects In C# With Example
Classes and Objects In C# With ExampleClasses and Objects In C# With Example
Classes and Objects In C# With Example
 
C# and Dot Net by Example
C# and Dot Net by ExampleC# and Dot Net by Example
C# and Dot Net by Example
 
Android OS
Android OSAndroid OS
Android OS
 
Beer vs wine by Sandip Murari
Beer vs wine by Sandip MurariBeer vs wine by Sandip Murari
Beer vs wine by Sandip Murari
 
Modern Management Thoughts
Modern Management ThoughtsModern Management Thoughts
Modern Management Thoughts
 
Proposal: A Study on Business Communucation System of KAZ Software
Proposal: A Study on Business Communucation System of KAZ SoftwareProposal: A Study on Business Communucation System of KAZ Software
Proposal: A Study on Business Communucation System of KAZ Software
 
Software Project Management: Release Notes
Software Project Management: Release NotesSoftware Project Management: Release Notes
Software Project Management: Release Notes
 
Software Project Management: Configuration Management
Software Project Management: Configuration ManagementSoftware Project Management: Configuration Management
Software Project Management: Configuration Management
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Software Requirements Specification on Bengali Braille to Text Translator
Software Requirements Specification on Bengali Braille to Text TranslatorSoftware Requirements Specification on Bengali Braille to Text Translator
Software Requirements Specification on Bengali Braille to Text Translator
 
Software Project Management: Testing Document
Software Project Management: Testing DocumentSoftware Project Management: Testing Document
Software Project Management: Testing Document
 
A pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architecturesA pattern based approach to the development of updm architectures
A pattern based approach to the development of updm architectures
 
Project Proposal: Bengali Braille to Text Translation
Project Proposal: Bengali Braille to Text TranslationProject Proposal: Bengali Braille to Text Translation
Project Proposal: Bengali Braille to Text Translation
 
Software Project Management: Project Planning
Software Project Management: Project PlanningSoftware Project Management: Project Planning
Software Project Management: Project Planning
 
Software Project Management: Change Control
Software Project Management: Change ControlSoftware Project Management: Change Control
Software Project Management: Change Control
 

Similar a C# example (Polymorphesim)

Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++Osama Al-Mohaia
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by HowardLearningTech
 
Howard type script
Howard   type scriptHoward   type script
Howard type scriptLearningTech
 
Type script by Howard
Type script by HowardType script by Howard
Type script by HowardLearningTech
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfaromanets
 
C# I need assitance on my code.. Im getting an error message Us.pdf
C# I need assitance on my code.. Im getting an error message Us.pdfC# I need assitance on my code.. Im getting an error message Us.pdf
C# I need assitance on my code.. Im getting an error message Us.pdfeyezoneamritsar
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfhullibergerr25980
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfarchgeetsenterprises
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfANJALIENTERPRISES1
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfaniyathikitchen
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4007laksh
 
I am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdfI am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdffortmdu
 
Rooms and MoreCan you please help me the JAVA programLabInherit.pdf
Rooms and MoreCan you please help me the JAVA programLabInherit.pdfRooms and MoreCan you please help me the JAVA programLabInherit.pdf
Rooms and MoreCan you please help me the JAVA programLabInherit.pdfmumnesh
 

Similar a C# example (Polymorphesim) (20)

Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
Howard type script
Howard   type scriptHoward   type script
Howard type script
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
C#
C#C#
C#
 
C# I need assitance on my code.. Im getting an error message Us.pdf
C# I need assitance on my code.. Im getting an error message Us.pdfC# I need assitance on my code.. Im getting an error message Us.pdf
C# I need assitance on my code.. Im getting an error message Us.pdf
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Modify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdfModify your solution for PLP04 to allow the user to choose the shape.pdf
Modify your solution for PLP04 to allow the user to choose the shape.pdf
 
Need to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdfNeed to revise working code below,A good design means the applicat.pdf
Need to revise working code below,A good design means the applicat.pdf
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
Hi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdfHi,I have updated your code. It is working fine now. Highllighted .pdf
Hi,I have updated your code. It is working fine now. Highllighted .pdf
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
C#.net
C#.netC#.net
C#.net
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4
 
P2
P2P2
P2
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
I am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdfI am trying to create a program That works with two other programs i.pdf
I am trying to create a program That works with two other programs i.pdf
 
Rooms and MoreCan you please help me the JAVA programLabInherit.pdf
Rooms and MoreCan you please help me the JAVA programLabInherit.pdfRooms and MoreCan you please help me the JAVA programLabInherit.pdf
Rooms and MoreCan you please help me the JAVA programLabInherit.pdf
 

C# example (Polymorphesim)

  • 1. Example In C# Shows How Object Oriented Is Classes/Polymorphesim Inherentence/Overloading & Overriding Done By:- MARWA SAMIH AL-AMRI
  • 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. 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. 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(); } } }