How to change static variable inside in a class by a method

No Name :

I have three classes:

Class One

public class One {
   private static Two object;

   public static void set_up(Two object) {
       int y = object.get();
       System.out.println(y);
   }

   public static void prn () {
       System.out.println(object.get());
   }

}  

Class Two

public class Two {
   private int x;


   public int get() {
       return x;
   }

   Two(int n){
       x = n;
   }
 }

Class Three

public class Three {
   public static void main( String[] argv ) {
       One st = new One();
       Two two = new Two(2);

       st.set_up(two);

       st.prn();
   }
}

I want to change the static variable object in class Two by method set_up(Two object). The problem is that static variable inside the class has the same name as the arguments in the method. How can I modify set_up(Two object) so I copy values from given argument to static object?

Mureinik :

You can qualify it by using the class' name:

public static void set_up(Two object) {
    One.object = object;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to access protected variable of class inside static method of the same class?

From Dev

how to change the value of a static variable from a static method of another class

From Dev

How to create an object inside class static method

From Dev

using static member variable of a class inside a method of this same class

From Dev

How to define a static variable inside a JS class

From Dev

How can a static method change a variable? (Java)

From Dev

Should I prefer final static variable inside class or final variable inside a static method

From Dev

How to reference static method from class variable

From Dev

C-like Static Variable inside a Python class method

From

call a static method inside a class?

From Dev

Static method inside another class

From Dev

How to change a normal method to a static method in an inherited class in c++?

From Dev

Java - How to change a method variable in the calling class?

From Dev

static variable inside static method in java

From Dev

python how to call static method from inside of a class body

From Dev

How do I use a static variable inside a class in Python

From Dev

Permanent change of a variable in static method

From Dev

How to change an instance variable of a class when that variable is inside a list

From Java

How to access parent class variable in child class inside a child method?

From Dev

How to access a Variable or list or dictionary inside a method of a class, outside the class?

From Java

How can static method access class variable in Python?

From Java

How can static method access class variable in Python?

From Dev

How to pass a class variable as a default value in a static method in Python

From Java

How do we change the value of a public variable inside a method?

From Dev

How to change the value of outside variable from inside the method

From Java

How to change variable value inside compare() method of Comparator

From Dev

static vs class as class variable/method (Swift)

From Dev

Call a static method inside other static method of a class in Javascript

From Dev

How to change value of a local variable inside an inner class?

Related Related

  1. 1

    How to access protected variable of class inside static method of the same class?

  2. 2

    how to change the value of a static variable from a static method of another class

  3. 3

    How to create an object inside class static method

  4. 4

    using static member variable of a class inside a method of this same class

  5. 5

    How to define a static variable inside a JS class

  6. 6

    How can a static method change a variable? (Java)

  7. 7

    Should I prefer final static variable inside class or final variable inside a static method

  8. 8

    How to reference static method from class variable

  9. 9

    C-like Static Variable inside a Python class method

  10. 10

    call a static method inside a class?

  11. 11

    Static method inside another class

  12. 12

    How to change a normal method to a static method in an inherited class in c++?

  13. 13

    Java - How to change a method variable in the calling class?

  14. 14

    static variable inside static method in java

  15. 15

    python how to call static method from inside of a class body

  16. 16

    How do I use a static variable inside a class in Python

  17. 17

    Permanent change of a variable in static method

  18. 18

    How to change an instance variable of a class when that variable is inside a list

  19. 19

    How to access parent class variable in child class inside a child method?

  20. 20

    How to access a Variable or list or dictionary inside a method of a class, outside the class?

  21. 21

    How can static method access class variable in Python?

  22. 22

    How can static method access class variable in Python?

  23. 23

    How to pass a class variable as a default value in a static method in Python

  24. 24

    How do we change the value of a public variable inside a method?

  25. 25

    How to change the value of outside variable from inside the method

  26. 26

    How to change variable value inside compare() method of Comparator

  27. 27

    static vs class as class variable/method (Swift)

  28. 28

    Call a static method inside other static method of a class in Javascript

  29. 29

    How to change value of a local variable inside an inner class?

HotTag

Archive