AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need some help with objects/classes

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
jobowoo@gmail.com
Guest





PostPosted: Wed Oct 25, 2006 12:21 am    Post subject: Need some help with objects/classes Reply with quote



Hello,

I'm trying to make my own object that holds a name of the link, the
href of that link and if that link has any sublinks/hrefs. BTW, this
code is written in C#, which is very similar to Java. Here is what I
have for my object (ArrayLink):



using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;

namespace FAModel
{
public class ArrayLink
{
private static string name;
private static string href;
private static ArrayList sublink;
private static ArrayList subhref;

public ArrayLink(string name2, string href2, ArrayList
sublink2, ArrayList subhref2)
{
name = name2;
href = href2;
sublink = sublink2;
subhref = subhref2;
}

public static string nameC
{
get
{
return name;
}
set
{
name = value;
}
}

public static string hrefC
{
get
{
return href;
}
set
{
href = value;
}
}

public static ArrayList sublinkC
{
get
{
return sublink;
}
set
{
sublink = value;
}
}

public static ArrayList subhrefC
{
get
{
return subhref;
}
set
{
subhref = value;
}
}
}
}



Here is my test code:



ArrayLink test1 = new ArrayLink("asdf", "asdf", null, null);
ArrayLink test2 = new ArrayLink("asdf2", "asdf", null, null);
ArrayLink test3 = new ArrayLink("asdf3", "asdf", null, null);
ArrayLink test4 = new ArrayLink("asdf4", "asdf", null, null);

When I test in debug mode, after running through test1...test4

test1..test4 all have the test4 information of "asdf4" and "asdf".
What am I doing wrong here? Thank you very much.
Back to top
Yan
Guest





PostPosted: Wed Oct 25, 2006 12:29 am    Post subject: Re: Need some help with objects/classes Reply with quote



Quote:
What am I doing wrong here?

you are using static variables and assign their values in the
constructor. the reason you see values from test4 is because test4 was
the last instance of ArrayLink class created. I suspect you want these
values to be 'per instance' as opposed to 'per class', so I think you
may want to remove the word 'static' from their declaration.
Back to top
Mishagam
Guest





PostPosted: Wed Oct 25, 2006 4:38 am    Post subject: Re: Need some help with objects/classes Reply with quote



jobowoo (AT) gmail (DOT) com wrote:
Quote:
Hello,

I'm trying to make my own object that holds a name of the link, the
href of that link and if that link has any sublinks/hrefs. BTW, this
code is written in C#, which is very similar to Java. Here is what I
have for my object (ArrayLink):



using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Text;
using System.Web;

namespace FAModel
{
public class ArrayLink
{
private static string name;
private static string href;
private static ArrayList sublink;
private static ArrayList subhref;

public ArrayLink(string name2, string href2, ArrayList
sublink2, ArrayList subhref2)
{
name = name2;
href = href2;
sublink = sublink2;
subhref = subhref2;
}

public static string nameC
{
get
{
return name;
}
set
{
name = value;
}
}

public static string hrefC
{
get
{
return href;
}
set
{
href = value;
}
}

public static ArrayList sublinkC
{
get
{
return sublink;
}
set
{
sublink = value;
}
}

public static ArrayList subhrefC
{
get
{
return subhref;
}
set
{
subhref = value;
}
}
}
}



Here is my test code:



ArrayLink test1 = new ArrayLink("asdf", "asdf", null, null);
ArrayLink test2 = new ArrayLink("asdf2", "asdf", null, null);
ArrayLink test3 = new ArrayLink("asdf3", "asdf", null, null);
ArrayLink test4 = new ArrayLink("asdf4", "asdf", null, null);

When I test in debug mode, after running through test1...test4

test1..test4 all have the test4 information of "asdf4" and "asdf".
What am I doing wrong here? Thank you very much.


You defined your fields static in here:

Quote:
private static string name;
private static string href;
private static ArrayList sublink;
private static ArrayList subhref;

what you expected? Do you know what static mean?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.