Question: My question is: why must we pass global variables(members, names) to an object if we want to use it. Isn't a global variable declared for all objects to have access to it?

```
public class Family {
    int members;
    String names;
    public Family(int members, string names) {
         this.members = members;
         this.names = names;    
    }
}

```

Answer: 
How else do you initialize the variables in an object?

Let me try to explain you this way, Suppose what you were asking was possible then, if we were to create 100 different family objects and if the variables were supposed to have different data, how will that be possible? Because changing a global field would affect all the objects right.

So basically when you create the object you either initialize the fields using a constructor as you have done in the sample or you can use a no args constructor and set the values after the object is created using "Setters".

For more understanding on initialization.

Refer: <https://www.google.com/amp/s/www.javaworld.com/article/3040564/java-101-class-and-object-initialization-in-java.amp.html>

Hope this helps.
The piece of code mentioned above is actually a **class** definition . Class is just a template which has member variables and member functions associated with it.Now **Object** is an instance of the class which has got some values for the variables which is generally get and set using getters and setters respectively.Other operations can be performed by member functions.Constructors are used to initialize the object.

```
public Family(int members, string names) {
     this.members = members;
     this.names = names;    
}

```

is a **paramaterized constructor** used to initialize the object with the parameters passed .This will obviously be useful while creating more than 1 objects of a class as each object will have different values associated with it.To be more clear:

```
public class Family {
int members;//member variable scope-class level
String names;//member variable scope-class level
public Family(int members, String names) {//int members,string names are parameters scope-constructor ,we can give any name to these two variables like int param_member,String param_names
     this.members = members;//LHS specifies the variable- member of the class and RHS specifies variable passed as parameter 
     this.names = names;  //LHS specifies the variable-names of the class and RHS specifies variable passed as parameter 
}

```

}