how do you get a value from a function and assigning that value to a variable?
Printable View
how do you get a value from a function and assigning that value to a variable?
ex:
class class_name{
int counter;
public int getCounter(){
return counter;
}
public void setCounter(int count){
counter = count;
}
|}
is there any way wherein we can get the value of counter then assign it to a different variable?
First, please put you code between code tags [code][/code] as shown.
Regards,Code:class Class_name{
int counter;
public int getCounter(){
return counter;
}
public void setCounter(int count){
counter = count;
}
}
/*
To use the above class to assign a value to another int, you can do something like
the following from another class. However, there may be visibility issues depending on how
you package your class, etc.
*/
Class_name cn = new Class_name();
cn.setCounter(10);
int val = cn.getCounter();
Jim
thanks Jim..
For the record, Java doesn't have functions. Java has methods.
db