using System;
namespace InheritanceApplication {
class Ship {
double ship_width;
double ship_length;
// Default constructor for class Ship
public Ship()
{
Width = Length = 0.0;
}
// Constructor for Ship get width and length of Ship
public Ship(double w, double l)
{
Width = w;
Length = l;
}
// Properties for Width
public double Width
{
get {
return ship_width;
}
set {
ship_width = value < 0 ? -value : value;
}
}
// Properties for Length
public double Length
{
get {
return ship_length;
}
set {
ship_length = value < 0 ? -value : value;
}
}
// display Ship status
public void ShipStatus()
{
Console.WriteLine("The ship width and length in metters are: Width "
+ Width + "| Length " + Length);
}
}
// A derived class of Ship named Interstellar_Ship.
class Interstellar_Ship : Ship {
string Interstellar_Engine;
// A default constructor of Interstellar_Ship.
public Interstellar_Ship()
{
Interstellar_Engine = "Velocity";
}
// Constructor base
public Interstellar_Ship(string s, double w, double l)
: base(w, l)
{
Interstellar_Engine = s;
}
// Return area of Interstellar_Ship.
public double Area()
{
return Width * Length;
}
// Display engine of Interstellar_Ship's.
public void DisplayInterstellar_Engine()
{
Console.WriteLine("Interstellar_Ship engine for " + Interstellar_Engine);
}
}
// Inheriting Interstellar_Ship class
class Speed_Interstellar_Ship : Interstellar_Ship {
int speed_ship;
// Constructor
public Speed_Interstellar_Ship(int speed, string s,
double w, double l)
: base(s, w, l)
{
speed_ship = speed;
}
// Display the speed.
public void Display_Speed()
{
Console.WriteLine("Speed in km/s is: " + speed_ship);
}
}
// Driver Class
class GFG {
// Main Method
public static void Main()
{
Speed_Interstellar_Ship first_ship = new Speed_Interstellar_Ship(131000,
"catafest Velocity Engine", 1000.33, 176.3);
Speed_Interstellar_Ship second_ship = new Speed_Interstellar_Ship(176000,
"mythcat Hybrid Variable-impulse Chemical", 177.0, 441.0);
Console.WriteLine("Details of first ship: ");
first_ship.DisplayInterstellar_Engine();
first_ship.ShipStatus();
first_ship.Display_Speed();
Console.WriteLine("Area of ship: " + first_ship.Area());
Console.WriteLine();
Console.WriteLine("Details of second_ship: ");
second_ship.DisplayInterstellar_Engine();
second_ship.ShipStatus();
second_ship.Display_Speed();
Console.WriteLine("Area of ship: " + second_ship.Area());
}
}
}