Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PolyMorphism
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Employee { public string name; // Basepay is defined as protected, so that it may be // accessed only by this class and derived classes. protected decimal basepay; // Constructor to set the name and basepay values. public Employee(string name, decimal basepay) { this.name = name; this.basepay = basepay; } // Declared virtual so it can be overridden. public virtual decimal CalculatePay() { return basepay; } } // Derive a new class from Employee. public class SalesEmployee : Employee { // New field that will affect the base pay. private decimal salesbonus; // The constructor calls the base-class version, and // initializes the salesbonus field. public SalesEmployee(string name, decimal basepay, decimal salesbonus) : base(name, basepay) { this.salesbonus = salesbonus; } // Override the CalculatePay method // to take bonus into account. public override decimal CalculatePay() { return basepay + salesbonus; } } /* Output: Employee4 Alice earned: 1500 Employee4 Bob earned: 1200 */ public class Program { public static void Main(string[] args) { //Create some new employees. SalesEmployee employee1 = new SalesEmployee("Alice",1000, 500); Employee employee2 = new Employee("Bob", 1200); //Employee employee2 = new SalesEmployee("Alice", 1000, 500); Console.WriteLine("Employee4 " + employee1.name + " earned: " + employee1.CalculatePay()); Console.WriteLine("Employee4 " + employee2.name + " earned: " + employee2.CalculatePay()); } } }
run
|
edit
|
history
|
help
0
pyramidalt
Fórum PS ➡ Converting a type (class category) to bool, implicitly ♦
Print 1 to 100 without using loop
Delegate, Method, List, Classes, Conditions
Random name switch
exception implicit toString
2.1 Basic types: Lists and Linq beauty
ParseIpRanges invalid character in string
Game v1.0.1
BNV