Difference between revisions of "Polymorphism"
(Created page with "Polymorphism is the term to describe inheritance trees of objects. A class can inherit subroutines from other classes, and can even overwrite them with its own iterations of t...") |
|||
Line 1: | Line 1: | ||
− | Polymorphism is the term to describe | + | Polymorphism is the term used to describe one method being able to take more than one type of input to process its code. |
− | + | <syntaxhighlight lang="csharp" line>public static void Main(string[] args) | |
− | + | { | |
− | + | int x = divide(15, 4); | |
+ | double y = divide(2.5, 0.5); | ||
+ | Console.WriteLine(x); | ||
+ | Console.WriteLine(y); | ||
+ | Console.ReadLine(); | ||
+ | /* writes: | ||
+ | * 3 | ||
+ | * 5.0 | ||
+ | */ | ||
+ | } | ||
+ | public static double divide(double a, double b) | ||
+ | { | ||
+ | return a / b; | ||
+ | } | ||
+ | public static int divide(int a, int b) | ||
+ | { | ||
+ | return a / b; | ||
+ | } |
Revision as of 19:04, 16 December 2016
Polymorphism is the term used to describe one method being able to take more than one type of input to process its code. <syntaxhighlight lang="csharp" line>public static void Main(string[] args)
{ int x = divide(15, 4); double y = divide(2.5, 0.5); Console.WriteLine(x); Console.WriteLine(y); Console.ReadLine(); /* writes: * 3 * 5.0 */ }
public static double divide(double a, double b)
{ return a / b; }
public static int divide(int a, int b)
{ return a / b; }