CSharp · Console
using System;
namespace ConsoleApp9
{
public class Cars
{
public int wheels;
public float speed;
public bool isworking;
public Cars(int wheels, float speed, bool isworking)
{
this.wheels = wheels;
this.speed = speed;
this.isworking = isworking;
}
//Создали конструктор с (int wheels, float speed, bool isworking) в скобках
//this. Помогает в будущем оставлять значения
public Cars() { }
//Создали конструктор с () в скобках, то есть пустой
public void GetValues()
{
Console.WriteLine("Колёса:" + this.wheels + " Скорость: " + this.speed + " Работает: " + this.isworking);
}
}
class Trucks : Cars
{
//Класс Trucks унаследовал всё от класса Cars
public int passangers;
public Trucks (int wheels, float speed, bool isworking, int passangers) : base(wheels, speed, isworking) {
//wheels, speed, isworking взяли из класса Cars
//C помощь base мы передали данные снова в базовый класс (Cars)
this.passangers = passangers;
}
}
public class MainClass
{
public static void Main()
{
Trucks Man = new Trucks(8, 185f, true, 8);
}
}
}