SlideShare une entreprise Scribd logo
1  sur  16
Polymorphism Compile time  polymorphism Run time polymorphism Method Hiding Virtual and  Overridden Methods Operators  overloading Functions/Methods overloading Inheritance Class/ Abstract Class   Interface
What is inheritance?   Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say "A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them.  If class A inherits from class B, then B is called Base Class of A. A is called subclass of B. Objects of a subclass can be used where objects of the corresponding Base Class  are expected. This is due to the fact that objects of the subclass share the same behavior as objects of the Base Class.  However, subclasses are not limited to the state and behaviors provided to them by their superclass. Subclasses can add variables and methods to the ones they inherit from the superclass.  In the literature you may also find other terms for "superclass" and "subclass". Superclasses are also called parent classes or base classes. Subclasses may also be called child classes or just derived classes.
Inheritance Example   Like a car, truck or motorcycles have certain common characteristics- they all have wheels, engines and brakes. Hence they all could be represented by a common class Vehicle which encompasses all those attributes and methods that are common to all types of vehicles.  However they each have their own unique attributes; car has 4 wheels and is smaller is size to a truck; whereas a motorcycle has 2 wheels. Thus we see a parent-child type of relationship here where the Car, Truck or Motorcycle can inherit certain Characteristics from the parent Vehicle; at the same time having their own unique attributes. This forms the basis of inheritance; Vehicle is the Parent, Super or the Base class. Car, Truck and Motorcycle become the Child, Sub or the Derived class.
Abstract Classes   Classes can be declared as abstract. This is accomplished by putting the keyword  abstract  before the keyword class in the class definition. The  abstract  keyword enables you to create classes and  class  members solely for the purpose of inheritance  public  abstract  class A { // Class members here.  }  An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class. Abstract classes may also define abstract methods. This is accomplished by adding the keyword abstract before the return type of the method. For example: public abstract class A { public abstract void DoWork(int i); }
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is  Polymorphism in C#  and  Object Oriented Programming (OOPS) Languages?   Object Oriented Programming (OOPS) Languages  In object-oriented programming,  polymorphism  is a generic term that means 'many shapes'. (from the Greek meaning "having multiple forms").  Polymorphism is briefly described as "one interface, many implementations."  polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.  Polymorphism in C# There are two types of polymorphism one is  compile time polymorphism  and the other is  run time polymorphism . Compile time polymorphism is functions and operators  overloading . Runtime time polymorphism is done using  inheritance (Override) and virtual functions . Here are some ways how we implement polymorphism in Object Oriented programming languages
Polymorphism Compile time  polymorphism Run time polymorphism Method Hiding Virtual and  Overridden Methods Operators  overloading Functions/Methods overloading
Function Overloading   Polymorphism means that functions assume different forms at different times. In case of compile time it is called function overloading. Two or more functions can have same name but their parameter list should be different either in terms of parameters or their data types. The functions  which differ only in their return types cannot be overloaded . The compiler will select the right function depending on the type of parameters passed.  Operator Overloading In polymorphism operators can also be overloaded ( Compile time polymorphism ). Operators can be overloaded in order to perform special functions with respect to the class. With the help of operator overloading standard operations such as + , - , * , etc can be applied on the objects of the class.
Inherited Methods   A method Foo() which is declared in the base class A and not redeclared in classes B or C is inherited in the two subclasses       using System;     namespace Polymorphism     {          class A         {             public void Foo() { Console.WriteLine("A::Foo () "); }         }          class B : A {}         class Test         {             static void Main(string[] args)             {                 A a = new A();                 a.Foo();   // output --> "A::Foo()"                 B b = new B();                  b .Foo();   // output --> "A::Foo()"             }         }   }
Casting        using System;     namespace Polymorphism     {          class A         {               public void Foo() { Console.WriteLine("A::Foo () "); }         }          class B : A         {               public void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();   // output --> "A::Foo()"                 b.Foo();   // output --> "B::Foo()"                 a = new B();                 a.Foo();   // output --> "A::Foo()"             }} }
Virtual and Overridden Methods  Only if a method is declared virtual, derived classes can override this method if they are explicitly declared to override the virtual base class method with the  override  keyword.       using System;     namespace Polymorphism     {          class A         {             public  virtual  void Foo() { Console.WriteLine("A::Foo () "); }         }          class B : A         {             public  override  void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();   // output --> "A::Foo()"                 b.Foo();   // output --> "B::Foo()"                 a = new B();                 a.Foo();   // output --> "B::Foo()"             }         }       }
Method Hiding   Why did the compiler in the second listing generate a warning? Because C# not only supports method overriding,  but also method hiding . Simply put, if a method is not overriding the derived method, it is hiding it. A hiding method has to be declared using the  new  keyword. The correct class definition in the second listing is thus:       using System;     namespace Polymorphism     {         class A         {             public void Foo() { Console.WriteLine("A::Foo () "); }         }         class B : A         {             public new void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();   // output --> "A::Foo()"                 b.Foo();   // output --> "B::Foo()"                 a = new B();                 a.Foo();   // output --> "A::Foo()"             }         }     }
The difference between override and new in C#  Case: override This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class. For instance: public class Base  { public virtual void SomeMethod()  {  }  } public class Derived : Base  { public override void SomeMethod()  {  }  } ...  Base b = new Derived(); b.SomeMethod(); will end up calling Derived.SomeMethod if that overrides Base.SomeMethod.
Case:New KeyWord if you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it. In that case, code like this: public class Base  {  public virtual void SomeOtherMethod() { }  } public class Derived : Base  {  public new void SomeOtherMethod() { }  } ...  Base b = new Derived();  Derived d = new Derived();  b.SomeOtherMethod();  d.SomeOtherMethod(); Will first call Base.SomeOtherMethod , then Derived.SomeOtherMethod . They're effectively two entirely separate methods which happen to have the same name, rather than the derived method overriding the base method.  If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).

Contenu connexe

Tendances

Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and InterfaceHaris Bin Zahid
 
Abstract & Interface
Abstract & InterfaceAbstract & Interface
Abstract & InterfaceLinh Lê
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classesShreyans Pathak
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
Abap Inicio
Abap InicioAbap Inicio
Abap Iniciounifor
 
Abstract class and interface
Abstract class and interfaceAbstract class and interface
Abstract class and interfaceMazharul Sabbir
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Javaparag
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceOUM SAOKOSAL
 
Java interfaces
Java interfacesJava interfaces
Java interfacesjehan1987
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Interface java
Interface java Interface java
Interface java atiafyrose
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationHoneyChintal
 

Tendances (20)

Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
Lecture 17
Lecture 17Lecture 17
Lecture 17
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Abstract class and Interface
Abstract class and InterfaceAbstract class and Interface
Abstract class and Interface
 
Abstract & Interface
Abstract & InterfaceAbstract & Interface
Abstract & Interface
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
javainterface
javainterfacejavainterface
javainterface
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
Abap Inicio
Abap InicioAbap Inicio
Abap Inicio
 
Abstract class and interface
Abstract class and interfaceAbstract class and interface
Abstract class and interface
 
Interfaces In Java
Interfaces In JavaInterfaces In Java
Interfaces In Java
 
Java OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & InterfaceJava OOP Programming language (Part 6) - Abstract Class & Interface
Java OOP Programming language (Part 6) - Abstract Class & Interface
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface
InterfaceInterface
Interface
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interface java
Interface java Interface java
Interface java
 
C# interview
C# interviewC# interview
C# interview
 
Interface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementationInterface in java ,multiple inheritance in java, interface implementation
Interface in java ,multiple inheritance in java, interface implementation
 

En vedette

Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1PRN USM
 
abitha-pds inheritance presentation
abitha-pds inheritance presentationabitha-pds inheritance presentation
abitha-pds inheritance presentationabitha ben
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritanceNurhanna Aziz
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
Unicity Sharing The Plan
Unicity Sharing The PlanUnicity Sharing The Plan
Unicity Sharing The PlanMatt Imperio
 
169 Ch 29_lecture_presentation
 169 Ch 29_lecture_presentation 169 Ch 29_lecture_presentation
169 Ch 29_lecture_presentationgwrandall
 

En vedette (13)

OPP
OPPOPP
OPP
 
File opp unicity
File opp unicityFile opp unicity
File opp unicity
 
Opp
OppOpp
Opp
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Lecture4
Lecture4Lecture4
Lecture4
 
abitha-pds inheritance presentation
abitha-pds inheritance presentationabitha-pds inheritance presentation
abitha-pds inheritance presentation
 
Chapter 04 inheritance
Chapter 04 inheritanceChapter 04 inheritance
Chapter 04 inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Unicity Sharing The Plan
Unicity Sharing The PlanUnicity Sharing The Plan
Unicity Sharing The Plan
 
Inheritance
InheritanceInheritance
Inheritance
 
169 Ch 29_lecture_presentation
 169 Ch 29_lecture_presentation 169 Ch 29_lecture_presentation
169 Ch 29_lecture_presentation
 
Inheritance
InheritanceInheritance
Inheritance
 

Similaire à Opps (20)

LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
C# program structure
C# program structureC# program structure
C# program structure
 
Java 06
Java 06Java 06
Java 06
 
Csci360 20 (1)
Csci360 20 (1)Csci360 20 (1)
Csci360 20 (1)
 
Csci360 20
Csci360 20Csci360 20
Csci360 20
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
C# concepts
C# conceptsC# concepts
C# concepts
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Java features
Java featuresJava features
Java features
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 

Plus de Lalit Kale

Serverless microservices
Serverless microservicesServerless microservices
Serverless microservicesLalit Kale
 
Develop in ludicrous mode with azure serverless
Develop in ludicrous mode with azure serverlessDevelop in ludicrous mode with azure serverless
Develop in ludicrous mode with azure serverlessLalit Kale
 
For Business's Sake, Let's focus on AppSec
For Business's Sake, Let's focus on AppSecFor Business's Sake, Let's focus on AppSec
For Business's Sake, Let's focus on AppSecLalit Kale
 
Introduction To Microservices
Introduction To MicroservicesIntroduction To Microservices
Introduction To MicroservicesLalit Kale
 
Dot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentalsDot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentalsLalit Kale
 
Code refactoring
Code refactoringCode refactoring
Code refactoringLalit Kale
 
Application Security Tools
Application Security ToolsApplication Security Tools
Application Security ToolsLalit Kale
 
Threat Modeling And Analysis
Threat Modeling And AnalysisThreat Modeling And Analysis
Threat Modeling And AnalysisLalit Kale
 
Application Security-Understanding The Horizon
Application Security-Understanding The HorizonApplication Security-Understanding The Horizon
Application Security-Understanding The HorizonLalit Kale
 
Coding guidelines
Coding guidelinesCoding guidelines
Coding guidelinesLalit Kale
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelinesLalit Kale
 
State management
State managementState management
State managementLalit Kale
 
Implementing application security using the .net framework
Implementing application security using the .net frameworkImplementing application security using the .net framework
Implementing application security using the .net frameworkLalit Kale
 
Data normailazation
Data normailazationData normailazation
Data normailazationLalit Kale
 
Versioning guidelines for product
Versioning guidelines for productVersioning guidelines for product
Versioning guidelines for productLalit Kale
 
Bowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinBowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinLalit Kale
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven DesignLalit Kale
 
Web 2.0 concept
Web 2.0 conceptWeb 2.0 concept
Web 2.0 conceptLalit Kale
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
 
How To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanHow To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanLalit Kale
 

Plus de Lalit Kale (20)

Serverless microservices
Serverless microservicesServerless microservices
Serverless microservices
 
Develop in ludicrous mode with azure serverless
Develop in ludicrous mode with azure serverlessDevelop in ludicrous mode with azure serverless
Develop in ludicrous mode with azure serverless
 
For Business's Sake, Let's focus on AppSec
For Business's Sake, Let's focus on AppSecFor Business's Sake, Let's focus on AppSec
For Business's Sake, Let's focus on AppSec
 
Introduction To Microservices
Introduction To MicroservicesIntroduction To Microservices
Introduction To Microservices
 
Dot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentalsDot net platform and dotnet core fundamentals
Dot net platform and dotnet core fundamentals
 
Code refactoring
Code refactoringCode refactoring
Code refactoring
 
Application Security Tools
Application Security ToolsApplication Security Tools
Application Security Tools
 
Threat Modeling And Analysis
Threat Modeling And AnalysisThreat Modeling And Analysis
Threat Modeling And Analysis
 
Application Security-Understanding The Horizon
Application Security-Understanding The HorizonApplication Security-Understanding The Horizon
Application Security-Understanding The Horizon
 
Coding guidelines
Coding guidelinesCoding guidelines
Coding guidelines
 
Code review guidelines
Code review guidelinesCode review guidelines
Code review guidelines
 
State management
State managementState management
State management
 
Implementing application security using the .net framework
Implementing application security using the .net frameworkImplementing application security using the .net framework
Implementing application security using the .net framework
 
Data normailazation
Data normailazationData normailazation
Data normailazation
 
Versioning guidelines for product
Versioning guidelines for productVersioning guidelines for product
Versioning guidelines for product
 
Bowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. MartinBowling Game Kata by Robert C. Martin
Bowling Game Kata by Robert C. Martin
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Web 2.0 concept
Web 2.0 conceptWeb 2.0 concept
Web 2.0 concept
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
How To Create Strategic Marketing Plan
How To Create Strategic Marketing PlanHow To Create Strategic Marketing Plan
How To Create Strategic Marketing Plan
 

Dernier

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIUdaiappa Ramachandran
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataSafe Software
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...DianaGray10
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdfJamie (Taka) Wang
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopBachir Benyammi
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxYounusS2
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 

Dernier (20)

KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
RAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AIRAG Patterns and Vector Search in Generative AI
RAG Patterns and Vector Search in Generative AI
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial DataCloud Revolution: Exploring the New Wave of Serverless Spatial Data
Cloud Revolution: Exploring the New Wave of Serverless Spatial Data
 
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
Connector Corner: Extending LLM automation use cases with UiPath GenAI connec...
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
20200723_insight_release_plan_v6.pdf20200723_insight_release_plan_v6.pdf
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
NIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 WorkshopNIST Cybersecurity Framework (CSF) 2.0 Workshop
NIST Cybersecurity Framework (CSF) 2.0 Workshop
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Babel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptxBabel Compiler - Transforming JavaScript for All Browsers.pptx
Babel Compiler - Transforming JavaScript for All Browsers.pptx
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 

Opps

  • 1. Polymorphism Compile time polymorphism Run time polymorphism Method Hiding Virtual and Overridden Methods Operators overloading Functions/Methods overloading Inheritance Class/ Abstract Class Interface
  • 2. What is inheritance? Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say "A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them. If class A inherits from class B, then B is called Base Class of A. A is called subclass of B. Objects of a subclass can be used where objects of the corresponding Base Class are expected. This is due to the fact that objects of the subclass share the same behavior as objects of the Base Class. However, subclasses are not limited to the state and behaviors provided to them by their superclass. Subclasses can add variables and methods to the ones they inherit from the superclass. In the literature you may also find other terms for "superclass" and "subclass". Superclasses are also called parent classes or base classes. Subclasses may also be called child classes or just derived classes.
  • 3. Inheritance Example Like a car, truck or motorcycles have certain common characteristics- they all have wheels, engines and brakes. Hence they all could be represented by a common class Vehicle which encompasses all those attributes and methods that are common to all types of vehicles. However they each have their own unique attributes; car has 4 wheels and is smaller is size to a truck; whereas a motorcycle has 2 wheels. Thus we see a parent-child type of relationship here where the Car, Truck or Motorcycle can inherit certain Characteristics from the parent Vehicle; at the same time having their own unique attributes. This forms the basis of inheritance; Vehicle is the Parent, Super or the Base class. Car, Truck and Motorcycle become the Child, Sub or the Derived class.
  • 4. Abstract Classes Classes can be declared as abstract. This is accomplished by putting the keyword abstract before the keyword class in the class definition. The abstract keyword enables you to create classes and class members solely for the purpose of inheritance public abstract class A { // Class members here. } An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class. Abstract classes may also define abstract methods. This is accomplished by adding the keyword abstract before the return type of the method. For example: public abstract class A { public abstract void DoWork(int i); }
  • 5.
  • 6.
  • 7.
  • 8. What is Polymorphism in C# and Object Oriented Programming (OOPS) Languages? Object Oriented Programming (OOPS) Languages In object-oriented programming, polymorphism is a generic term that means 'many shapes'. (from the Greek meaning "having multiple forms"). Polymorphism is briefly described as "one interface, many implementations." polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. Polymorphism in C# There are two types of polymorphism one is compile time polymorphism and the other is run time polymorphism . Compile time polymorphism is functions and operators overloading . Runtime time polymorphism is done using inheritance (Override) and virtual functions . Here are some ways how we implement polymorphism in Object Oriented programming languages
  • 9. Polymorphism Compile time polymorphism Run time polymorphism Method Hiding Virtual and Overridden Methods Operators overloading Functions/Methods overloading
  • 10. Function Overloading Polymorphism means that functions assume different forms at different times. In case of compile time it is called function overloading. Two or more functions can have same name but their parameter list should be different either in terms of parameters or their data types. The functions which differ only in their return types cannot be overloaded . The compiler will select the right function depending on the type of parameters passed. Operator Overloading In polymorphism operators can also be overloaded ( Compile time polymorphism ). Operators can be overloaded in order to perform special functions with respect to the class. With the help of operator overloading standard operations such as + , - , * , etc can be applied on the objects of the class.
  • 11. Inherited Methods A method Foo() which is declared in the base class A and not redeclared in classes B or C is inherited in the two subclasses     using System;     namespace Polymorphism     {         class A         {             public void Foo() { Console.WriteLine("A::Foo () "); }         }         class B : A {}         class Test         {             static void Main(string[] args)             {                 A a = new A();                 a.Foo();  // output --> "A::Foo()"                 B b = new B();                 b .Foo();  // output --> "A::Foo()"             }         }   }
  • 12. Casting     using System;     namespace Polymorphism     {         class A         {               public void Foo() { Console.WriteLine("A::Foo () "); }         }         class B : A         {               public void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();  // output --> "A::Foo()"                 b.Foo();  // output --> "B::Foo()"                 a = new B();                 a.Foo();  // output --> "A::Foo()"             }} }
  • 13. Virtual and Overridden Methods Only if a method is declared virtual, derived classes can override this method if they are explicitly declared to override the virtual base class method with the override keyword.     using System;     namespace Polymorphism     {         class A         {             public virtual void Foo() { Console.WriteLine("A::Foo () "); }         }         class B : A         {             public override void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();  // output --> "A::Foo()"                 b.Foo();  // output --> "B::Foo()"                 a = new B();                 a.Foo();  // output --> "B::Foo()"             }         }      }
  • 14. Method Hiding Why did the compiler in the second listing generate a warning? Because C# not only supports method overriding, but also method hiding . Simply put, if a method is not overriding the derived method, it is hiding it. A hiding method has to be declared using the new keyword. The correct class definition in the second listing is thus:     using System;     namespace Polymorphism     {         class A         {             public void Foo() { Console.WriteLine("A::Foo () "); }         }         class B : A         {             public new void Foo() { Console.WriteLine("B::Foo () "); }         }         class Test         {             static void Main(string[] args)             {                 A a;                 B b;                 a = new A();                 b = new B();                 a.Foo();  // output --> "A::Foo()"                 b.Foo();  // output --> "B::Foo()"                 a = new B();                 a.Foo();  // output --> "A::Foo()"             }         }     }
  • 15. The difference between override and new in C# Case: override This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class. For instance: public class Base { public virtual void SomeMethod() { } } public class Derived : Base { public override void SomeMethod() { } } ... Base b = new Derived(); b.SomeMethod(); will end up calling Derived.SomeMethod if that overrides Base.SomeMethod.
  • 16. Case:New KeyWord if you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it. In that case, code like this: public class Base { public virtual void SomeOtherMethod() { } } public class Derived : Base { public new void SomeOtherMethod() { } } ... Base b = new Derived(); Derived d = new Derived(); b.SomeOtherMethod(); d.SomeOtherMethod(); Will first call Base.SomeOtherMethod , then Derived.SomeOtherMethod . They're effectively two entirely separate methods which happen to have the same name, rather than the derived method overriding the base method. If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).