Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Encapsulation and abstration
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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 } } }
Show compiler warnings
[
+
]
Show input
fork mode
|
history
|
discussion
stackse - search stackoverflow differently