java snippet help

R

rodchar

hi all,

i have this following java snippet i'm trying to convert to c# for practice.

public class Disk extends ComponentDecorator
{
Computer computer;

public Disk(Computer c)
{
computer = c;
}

public String description()
{
return computer.description() + " and a disk";
}
}


Tester code:
Computer computer = new Computer();
computer = new Disk(computer)
Console.WriteLine("You're getting " + computer.Description);
//This should say "You're getting a computer and a disk."

Ques 1: How do you code"extends" in C#
Ques 2: C# won't let me define description() method as shown above. It
want's me to override or use new keyword. Why?

thanks,
rodchar
 
R

rodchar

Here's some additional information to (hopefully) clarify more:
Basically the whole code in a nutshell:

public class CLASS_A {
public string foo() {
return "Hello";
}
}

public abstract class CLASS_B extends CLASS_A {
public abstract string foo();
}

public class CLASS_C extends CLASS_B {
CLASS_A class_a;
public CLASS_C(CLASS_A a) {
class_a = a;
}
public String foo() {
return class_a.foo() + " World!";

static void Main(string[] args) {
CLASS_A a = new CLASS_A();
a = new CLASS_C(a);
Console.WriteLine("You wrote {0}", a.foo());
// "You wrote Hello World"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top