Hi I am new to the java programming. I have a instance variable in a class which I should call to another class.It should not be static as per the requirements.The code given below## `
public class Card {
private String no;
private String text;
public Vector totalCards = new Vector();
public String getNo() {
totalCards.addElement(no);
return no;
}
public void setNo(String no) {
this.no = no;
}
public String getText() {
totalCards.addElement(text);
return text;
}
public void setText(String text) {
this.text = text;
}
}
I need to pass this “totalCards” vector in another class without making it as a static.How can I pass this value.Can anybody help me. Any suggestions appreciated.
It’s a bit unclear exactly what your issue is, but you first need to have an instance of Card. The totalCards Vector will then live in that Card object.
Now the object that has access to myCards can access the Vector with:
However, it’s considered a better practice by many to make totalCards private and make a getter for it: