The document defines an abstract Vehicle class with protected string color and int year properties. It also defines a Car class that inherits from Vehicle. The Main method creates a Car object, sets its color to "Red" and year to 2005. This establishes an inheritance hierarchy where Car inherits from Vehicle and allows setting color and year values on the Car instance.
The document defines an abstract Vehicle class with protected string color and int year properties. It also defines a Car class that inherits from Vehicle. The Main method creates a Car object, sets its color to "Red" and year to 2005. This establishes an inheritance hierarchy where Car inherits from Vehicle and allows setting color and year values on the Car instance.
{ public string color { get; set; } public int year { get; set; } }
abstract class Vehicle
{ protected string color { get; set; } protected int year { get; set; } public string Color { get { return this.color; } set { this.color = value; } }
class Car : Vehicle
{ public Car() { } // empty constructor public Car( string c, int y) // constructor { this.color = c; this.year = y; } } class Program { static void Main(string[] args) { Car bmw = new Car(Red, 2005); } }
abstract class Vehicle
{ protected string color; protected int year;
<
public string Year
{ get { return this.year; } set { this.year = value; } } } class Car : Vehicle { } class Program { static void Main(string[] args) { Car bmw = new Car(); bmw.Color = Red; bmw.Year = 2005;
Public = Can be called from anywhere.
Protected = Can be called only inside and from child classes. Private = Can be called only inside a class = Encapsulation.
} }
Static = Can be called without instantiation.
no Static = Needs to be instantiated before calling.
public string getColor()
{ return this.color; } public void setColor(string c) { this.color = c; }
<
public int getYear()
{ return this.year; } public void setYear(string y) { this.year = y; } } class Car : Vehicle { } class Program { static void Main(string[] args) { Car bmw = new Car();
Void = Does something. Returns nothing.
int, string, oat, double, bool, Car = Does something and returns a value of selected type. Virtual = The method is declared in the abstract class for inheritance. Can be overridden in a child class. Override = Overrides the parent method.