Inherits class (C#)
<%@ page Language="c#" runat="server" %> <script runat="server"> public class ScientificCalculator : Calculator { public void SquareRoot() { double root = Math.Sqrt(CurrentValue); Clear(); Add(root); } } public class Calculator { private double currentValue; public double CurrentValue { get { return currentValue; } } public void Add(double addValue) { currentValue += addValue; } public void Subtract(double subValue) { currentValue -= subValue; } public void Multiply(double multValue) { currentValue *= multValue; } public void Divide(double divValue) { currentValue /= divValue; } public void Clear() { currentValue = 0; } } void Page_Load() { ScientificCalculator MyCalc = new ScientificCalculator(); Response.Write("<b>Created a new ScientificCalculator object.</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.Add(23); Response.Write("<br/><b>Added 23 - MyCalc.Add(23)</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.Subtract(7); Response.Write("<br/><b>Subtracted 7 - MyCalc.Subtract(7)</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.Multiply(3); Response.Write("<br/><b>Multiplied by 3 - MyCalc.Multiply(3)</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.Divide(4); Response.Write("<br/><b>Divided by 4 - MyCalc.Divide(4)</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.SquareRoot(); Response.Write("<br/><b>Square root - MyCalc.SquareRoot()</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); MyCalc.Clear(); Response.Write("<br/><b>Cleared - MyCalc.Clear()</b><br/>"); Response.Write("Current Value = " + MyCalc.CurrentValue); } </script>