0% found this document useful (0 votes)
45 views

Empty Constructor // Constructor: Vehicle Vehicle Vehicle

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.

Uploaded by

pseudocod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Empty Constructor // Constructor: Vehicle Vehicle Vehicle

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.

Uploaded by

pseudocod
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

abstract class Vehicle

{
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.

bmw.setColor(Red);
bmw.setYear(2005);
}
}

You might also like