Created
July 18, 2020 17:38
-
-
Save nanwang2016/9ab84b87f8c5e43419ae0bfebce6db6b to your computer and use it in GitHub Desktop.
Demonstration of Private and Public Access Specifier in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Private_Public | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Calculator Plus = new Calculator(); | |
Plus.Acceptdetails(); | |
Plus.Display(); | |
Console.ReadLine(); | |
} | |
} | |
class Calculator | |
{ | |
//member variables | |
private double a; | |
private double b; | |
public void Acceptdetails() | |
{ | |
Console.WriteLine("Enter a: "); | |
a = Convert.ToDouble(Console.ReadLine()); | |
Console.WriteLine("Enter b: "); | |
b = Convert.ToDouble(Console.ReadLine()); | |
} | |
public double Plus() | |
{ | |
return a+b; | |
} | |
public void Display() | |
{ | |
Console.WriteLine("a: {0}", a); | |
Console.WriteLine("b: {0}", b); | |
Console.WriteLine("total: {0}", Plus()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment