Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Encapsulation and abstration
//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 Bike { public int mileage = 65; public string color = "Black"; private string formula="a*b" ; //Its public – so accessible outside class public int GetMileage() { return mileage; } //Its public – so accessible outside class public string GetColor() { return color; } //Its private – so not accessible outside class private string GetEngineMakeFormula() { return formula; } //Its public – so accessible outside class public string DisplayMakeFormula() { //"GetEngineMakeFormula()" is private but accessible and limited to this class only return GetEngineMakeFormula(); } } public class Program { public static void Main(string[] args) { Bike objBike = new Bike(); Console.WriteLine("Bike mileage is : " + objBike.GetMileage()); //accessible outside "Bike" Console.WriteLine("Bike color is : " + objBike.GetColor()); //accessible outside "Bike" //we can't call this method as it is inaccessible outside "Bike" //objBike.GetEngineMakeFormula(); //commented because we can't access it Console.WriteLine("Bike formula is : " + objBike.DisplayMakeFormula()); //accessible outside } } }
run
|
edit
|
history
|
help
0
Remove BOLD formatting from html
Finding occurances of a value in the elements of a list
Comparing hashing with different encoding and also transferring bytes
Intuit // C# // listing_4.9 (do_while // kupi_slonika
TestKlasse
caleb
Salario
p link gener tor
Fórum ➡ GroupJoin'ing Books and Orders ( with Zip'ped output ) ♦
Selection Sort