Task: Implementation of Interfaces
Realize the following UML class diagram and following Python code in Java code!
import time
now=time.localtime()
class Date:
def __init__(self):
self._day=now.tm_mday
self._month=now.tm_mon
self._year=now.tm_year
def getDay(self):
return self._day
def getMonth(self):
return self._month
def getYear(self):
return self._year
class Time:
def __init__(self):
self._second=now.tm_sec
self._minute=now.tm_min
self._hour=now.tm_hour
def getSecond(self):
return self._second
def getMinute(self):
return self._minute
def getHour(self):
return self._hour
class DateTime(Date, Time):
def __init__(self):
Date.__init__(self)
Time.__init__(self)
dt=DateTime()
print("Date: %02d.%02d.%4d\tTime: %02d:%02d:%02d"% (dt.getDay(),dt.getMonth(),dt.getYear(),dt.getHour(),dt.getMinute(),dt.getSecond()))
Note that multiple inheritance of concrete classes is not allowed in Java, but multiple interface implementations are.