-
static method
I have a static method with argument number,
public static int newNumber(number)
{
callatz sequence etc
i need to access the value of the parameter(number) from a non static method just so confused on how to do this,
public void print()
i need to access the values so i can:
Systme.out.print(number).
anybody have any ideas.
i would rather a point in the right direction.
thankyou :)-: ... Shift+R improves the quality of this image. CTRL+F5 reloads the whole page.
-
Re: static method
-
Re: static method
Static/non-static aside, parameters to a method are local to that method. You cannot access them outside that method. Time to rethink your design.
-
Re: static method
-
Re: static method
Hi Katie,
I agree it can get confusing. I also agree with previous posters it might be a good idea to rethink the design. I put together a little example based on what you need as a starting point:
Code:
class PrintNewNumber {
private int number;
public PrintNewNumber(int number1){
this.number = number1;
System.out.println(number);
PrintNumberAgainButAcceptAnyNumber(number);
PrintNumberAgainButAcceptAnyNumber(20);
PrintTheOriginalAgain();
}
public static void main (String args[]) {
new PrintNewNumber(13);
}
static void PrintNumberAgainButAcceptAnyNumber(int number2) {
System.out.println(number2);
}
private void PrintTheOriginalAgain( ) {
System.out.println(number);
}
}