Question

What is wrong with this code snippet? Explain why it is wrong. Fix it public abstract...

 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() { }
    }

Homework Answers

Answer #1
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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Identify and explain which type of polymorphism technique is used in the following code A- class...
Identify and explain which type of polymorphism technique is used in the following code A- class Calculator { public void add(int i, int j) { System.out.println("Integer addition"); } public void add(int i, double j) { System.out.println("Integer and double addition"); } public void add(double i, double j) { System.out.println("Double addition"); } } B- public class MyClass { void test(int a) { System.out.println("a: " + a); } void test(int a, int b) { System.out.println("a and b: " + a + "," +...
About python: Explain what is Polymorphism and provide a code snippet
About python: Explain what is Polymorphism and provide a code snippet
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have...
I am writing code in java to make the design below. :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) :-):-):-):-):-):-)  :-):-):-):-):-):-)  :-):-):-):-):-):-) I already have this much public class Main { int WIDTH = 0; double HEIGHT = 0; public static void drawSmileyFaces() { System.out.println(" :-):-):-):-):-):-)"); } public static void main (String[] args) { for (int WIDTH = 0; WIDTH < 3; WIDTH++ ) { for(double HEIGHT = 0; HEIGHT < 2; HEIGHT++) { drawSmileyFaces(); } } } } I am pretty sure that alot of this is wrong...
1) Explain the problem with the following code segment and suggest a way to fix it....
1) Explain the problem with the following code segment and suggest a way to fix it. int i = 42; int *p1, *p2; p1 = &i; *p2 = *p1; 2) What are the Invariants for the bag class that uses a static array?  (Hints: explain the functionality of the class’s private member variables – used and data).
) Explain in your own words what is wrong with, and how you might fix, the...
) Explain in your own words what is wrong with, and how you might fix, the following statement. “The series from n=1 to infinity 1/(2n^2−1) is convergent by the Direct Comparison Test”
JAVA What values are stored in variables a and b in the code below? public class...
JAVA What values are stored in variables a and b in the code below? public class StackQuestion { public static void main(String[] args) { Stack s = new Stack(); s.push(1); s.push(2); s.push(3); s.pop(); s.pop(); s.push(4); s.push(5); s.pop(); s.pop(); int a = s.pop(); s.push(6); int b = s.pop(); } } What numbers are stored in variable a and b when the code below executes? public class QueueQuestion { public static void main(String[] args) { Queue s = new Queue(); s.enqueue(1); s.enqueue(2);...
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i...
Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i + 1 ); Here is a skeleton for class Thing: class Thing { public interface Mystery { ????? } public void method( Mystery param ) { // body of method omitted } } Which text below would work where ????? is given above: a) void method( int i ); b) int method( int i ); c) abstract int method( int i ); d) abstract...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } } Select one: a)Each case section must end with a break statement. b)The case label 0 must precede case label 1. c)There is nothing wrong with the Java code. d)The default label must be the last label in the switch statement. e)The variable x does...
Hello. I have an assignment that is completed minus one thing, I can't get the resize...
Hello. I have an assignment that is completed minus one thing, I can't get the resize method in Circle class to actually resize the circle in my TestCircle claass. Can someone look and fix it? I would appreciate it! If you dont mind leaving acomment either in the answer or just // in the code on what I'm doing wrong to cause it to not work. That's all I've got. Just a simple revision and edit to make the resize...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT