Question: I have a static reference variable 

```
static IMail mailer = null;

```

to which I am assigning a value in the constructor of the class SearchManager

```
public SearchManager(ILog logger, String basePath, String indexPath, String nwId, IMail mailer) {
        this.logger = logger;
        this.basePath = basePath;
        this.indexPath = indexPath;
        this.nwId = nwId;
        this.mailer = mailer;
    } 

```

and I am using the mailer in my code. The constructor of this class might be called multiple times. So I have a query that how this static reference variable will behave each time the constructor is called. Will it take only the value which I passes when I called the constructor the first time or will it take different values each time I call the constructor?

Answer: 
First of all you **should not use 'this' keyword with static variable**. You can do the following(not recommended though)

```
public SearchManager(ILog logger, String basePath, String indexPath, String nwId, IMail mailerarg) {
        this.logger = logger;
        this.basePath = basePath;
        this.indexPath = indexPath;
        this.nwId = nwId;
        mailer = mailerarg;
    } 

```

and **Yes it being a static variable will change every time you create a new object of the Class**.Static variables belong to Class rather than it's individual instances. So whenever you change it's value it will be reflected in all the corresponding class objects(All objects have their class information).
> 
> Will it take only the value which I passes when I called the constructor the first time or will it take different values each time I call the constructor?
> 
> 
> 

It will take different values each time you call the constructor.

Static variables are not particularly special. When you assign a value to variable, the variable takes that value. This is equally true of static variables, so if you assign a static variable multiple times, its value will be updated each time.

---

In this case, if you're calling a contructor (potentially) multiple times with different arguments, it sounds very much like this should be an instance-spceific field, rather than a single static variable. That way, each `SearchManager` has a reference to the `mailer` that *it* was constructed with, rather than the mailer of the manager that happened to be constructed most recently.

Even if you don't agree with this, and feel that there should be a single `mailer` for the whole application, I would suggest you change the way it's currently managed. Values passed into constructors tend to be used for *that* instance. Setting static variables in constructors is thus potentially very confusing, and it would be better to make an explicit call to something like `MailerSupport.setGlobalMailer(mailer)` instead whenever you wanted to change the value.