dlang-book/book/06-классы-объектно-ориентированный-стиль/src/chapter-6-4/app.d

39 lines
776 B
D

class Contact
{
string bgColor()
{
return "Серый";
}
}
class Friend : Contact
{
string currentBgColor = "Светло-зеленый";
string currentReminder;
this(ref string c)
{
currentBgColor = c;
}
override string bgColor()
{
return currentBgColor;
}
string reminder()
{
return currentReminder;
}
}
unittest
{
string startColor = "Синий";
Friend f = new Friend(startColor);
Contact c = f; // Подставить экземпляр класса Friend вместо экземпляра класса Contact
auto color = c.bgColor(); // Вызвать метод класса Friend
import std.stdio : writeln;
writeln(color);
}