using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OopsConcept
{
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;
}
}
public class hondaBike
{
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 Programabst
{
public static void Main(string[] args)
{
Console.WriteLine("------------------------------------Encapsulation started here------------------------------------");
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("------------------------------------Encapsulation End here------------------------------------");
Console.WriteLine("------------------------------------Abstraction Started here------------------------------------");
hondaBike objhondaBike = new hondaBike();
Console.WriteLine("Bike mileage is : " + objhondaBike.GetMileage()); //accessible outside "Bike"
Console.WriteLine("Bike color is : " + objhondaBike.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 making frmula is : " + objhondaBike.DisplayMakeFormula()); //accessible outside
Console.WriteLine("------------------------------------Abstraction End here------------------------------------");
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OopsConcept
{
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;
}
}
public class hondaBike
{
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 Programabst
{
public static void Main(string[] args)
{
Console.WriteLine("------------------------------------Encapsulation started here------------------------------------");
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("------------------------------------Encapsulation End here------------------------------------");
Console.WriteLine("------------------------------------Abstraction Started here------------------------------------");
hondaBike objhondaBike = new hondaBike();
Console.WriteLine("Bike mileage is : " + objhondaBike.GetMileage()); //accessible outside "Bike"
Console.WriteLine("Bike color is : " + objhondaBike.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 making frmula is : " + objhondaBike.DisplayMakeFormula()); //accessible outside
Console.WriteLine("------------------------------------Abstraction End here------------------------------------");
Console.Read();
}
}
}
No comments:
Post a Comment