473,395 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

java snippet help

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

Oct 21 '08 #1
3 1254
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"

"rodchar" wrote:
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
Oct 21 '08 #2
On Tue, 21 Oct 2008 06:12:01 -0700, rodchar
<ro*****@discussions.microsoft.comwrote:
[...]
Ques 1: How do you code"extends" in C#
http://msdn.microsoft.com/en-us/library/0b0thckt.aspx
Ques 2: C# won't let me define description() method as shown above. It
want's me to override or use new keyword. Why?
http://msdn.microsoft.com/en-us/library/9fkccyh4.aspx
http://msdn.microsoft.com/en-us/library/ebca9ah3.aspx
Oct 21 '08 #3
thanks for point in right direction,
rod.

"Peter Duniho" wrote:
On Tue, 21 Oct 2008 06:12:01 -0700, rodchar
<ro*****@discussions.microsoft.comwrote:
[...]
Ques 1: How do you code"extends" in C#

http://msdn.microsoft.com/en-us/library/0b0thckt.aspx
Ques 2: C# won't let me define description() method as shown above. It
want's me to override or use new keyword. Why?

http://msdn.microsoft.com/en-us/library/9fkccyh4.aspx
http://msdn.microsoft.com/en-us/library/ebca9ah3.aspx
Oct 23 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web...
1
by: M.E. | last post by:
I have explained at the linked below my problem. Basically it is a Java code .. It is a dropdown box. when you select an item it goes to another text area .. You can add items to that text area....
18
by: Rick | last post by:
Hi, We all know that Java has classes but how about basic storage objects like structs? C and C++ have Structs, Pascal has Records, Visual Basic has Types etc. How about Java? Greetings, Rick
12
by: steven acer | last post by:
hello, i have a java app that constructs an xml from a specific file format and vice versa. i've been asked to convert it to c++, but im not an expert in c++, actually im mere beginner you can...
0
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build...
1
by: Piet71 | last post by:
Hi, I have a stylesheet to select nodes from a source document via their "position" attribute. The template snippet is as follows: <xsl:template match="counter"> <xsl:if test="$number"><!--@pos=2...
1
by: HxRLxY | last post by:
I have a program that shows a thumbnail of an image. If the user clicks on the thumbnail a new JFrame is opened that shows the full size image. If the image is larger than the screen, it gets...
7
by: svpriyan | last post by:
Dear Buddies, I have two Java Prog: My task is to read the Content of the file and write to an XML file. so i started doing it perfectly... What i have problem is when i tried to execute the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.