What is wrong with this code snippet? Explain why it is wrong. Fix it public abstract class Clock { public DateTime GetTime() { return DateTime.Now; } } public abstract class Radio { public void SetStation(double freq) { } public void PlayRadio() { } } public class AlarmClock : Clock, Radio { public void SetAlarm(DateTime time) { } public void SnoozeAlarm() { } }
Error: public class AlarmClock : Clock, Radio { Multiple inheritance is not allowed in C#. So class AlarmClock cannot inherit two classes Clock and Radio. Error fixing:
public abstract class Clock { public DateTime GetTime() { return DateTime.Now; } } public abstract class Radio : Clock { public void SetStation(double freq) { } public void PlayRadio() { } } public class AlarmClock : Radio { public void SetAlarm(DateTime time) { } public void SnoozeAlarm() { } }
Used multilevel inheritance above.
Do ask if any doubt.
Get Answers For Free
Most questions answered within 1 hours.