5 Replies Latest reply on Nov 12, 2012 9:44 AM by Kayaman

    How to make class only initial once and be called to share a variable?

      I have a class,like follows:
      public class demo{
      private int a1;
      private boolean available=false;
      public synchronized void set(int value){
      public synchronized int get(){
      return a1;

      I make another two class to call demo class,in aa class,I set a1=5 under demo,

      public class aa{
      public void setvalue{
      demo d=new demo();

      And get value from like follows:

      public class bb{
      public void getvalue(){
      demo d=new demo();

      My question,how to make demo class can be initial once and make invoked by many class,but share a variable?