Sei sulla pagina 1di 1

abstract class Vehicle abstract class Vehicle abstract class Vehicle

{ { {
public string color { get; set; } protected string color { get; set; } protected string color;
public int year { get; set; } protected int year { get; set; } protected int year;
}
public string Color public string getColor()
class Car : Vehicle { {
{ get { return this.color; } return this.color;
public Car() { } // empty constructor set { this.color = value; } }
}
public Car( string c, int y) // constructor public void setColor(string c)
{ public string Year {
this.color = c; { this.color = c;
this.year = y; get { return this.year; }

< <
}
} set { this.year = value; }
} } public int getYear()
} {
class Program return this.year;
{ class Car : Vehicle }
static void Main(string[] args) {
{ } public void setYear(string y)
Car bmw = new Car(Red, 2005); {
} class Program this.year = y;
} { }
static void Main(string[] args) }
{
Car bmw = new Car(); class Car : Vehicle
{
bmw.Color = Red; }
bmw.Year = 2005;
Public = Can be called from anywhere. } class Program
Protected = Can be called only inside and from child classes. } {
Private = Can be called only inside a class = Encapsulation. static void Main(string[] args)
Static = Can be called without instantiation. {
no Static = Needs to be instantiated before calling. Car bmw = new Car();

Void = Does something. Returns nothing. bmw.setColor(Red);


int, string, oat, double, bool, Car = Does something and returns a value of selected type. bmw.setYear(2005);
Virtual = The method is declared in the abstract class for inheritance. Can be overridden in a child class. }
Override = Overrides the parent method. }

Potrebbero piacerti anche