Answer the question
In order to leave comments, you need to log in
How to pass default data from one class to another?
I can't pass data from one default class constructor to another.
Here is the code of the first class to pass to:
internal class Airplane
{
protected string StartCity;
protected string FinishCity;
protected Date StartDate;
protected Date FinishDate;
public Airplane()
{
StartCity = "London";
FinishCity = "Lviv";
StartDate = new Date(2222,12,4,12,42);
FinishDate = new Date(2222,12,5,6,12);
}
public Airplane(string startCity, string finishCity)
{
StartCity = startCity;
FinishCity = finishCity;
}
public Airplane(Airplane obj)
{
StartCity=obj.StartCity;
FinishCity=obj.FinishCity;
StartDate = new Date(obj.StartDate);
FinishDate = new Date(obj.FinishDate);
}
}
internal class Date
{
protected int Year;
protected int Month;
protected int Day;
protected int Hours;
protected int Minutes;
public Date()
{
Year = 2022;
Month = 1;
Day = 11;
Hours = 12;
Minutes = 20;
}
public Date(int year, int month, int day, int hours, int minutes)
{
Year = year;
Month = month;
Day = day; ;
Hours = hours;
Minutes = minutes;
}
public Date(Date obj)
{
this.Year = obj.Year;
this.Month = obj.Month;
this.Day = obj.Day;
this.Hours = obj.Hours;
this.Minutes = obj.Minutes;
}
}
Answer the question
In order to leave comments, you need to log in
When you try to display on the screen, you do not display the date and the class itself, since you do not have a method for displaying it on the screen. To facilitate the task, I suggest you make a method of the PrintInfo () type that will print all the necessary data of this class to the screen when called
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question