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
Program 1
Namespace addition
1
nthFromLastElement
Lambdas
HelloWorld
Simple Parallel.For example
ANQ Bug with Feb month display
cup tournament prediction
Concatenate string with null.