Java Reference
In-Depth Information
No discussion on an object oriented programming language will be complete if we have not
discussed objects. When we create classes in our source code, we are actually creating a tem-
plate for objects. When we run our source code, our classes turn out in form of objects. These
objects contain a copy of the methods and variables we have defined inside our class. The
most important aspects of objects is about how they behave when many users or other com-
puter programs access our program in runtime. Suppose 10 users access the runtime concur-
rently. If each user will have the same values of variables and methods we have defined in
the class? What if users access our runtime at different times then what will be impact on
values of our methods and variables? If you like to discuss this issue in some other words
then actually we are talking of state of objects at various times. In what state an object is
currently in and in what state it will be for different users over time?
Due to these reasons, thorough understanding of how objects behave is required. Otherwise
your component design will go wrong.
Some important aspects about objects:
When objects are created, they have their own data type. Objects can be assigned to a vari-
able just like methods or other variables.
You create an object by using the “new” keyword. If you have created a class my_class then
here are the statements to create objects from this class:
My_object1 = new my_class;
My_object2 = new my_class;
My_object3 = new my_class;
Here we have created 3 objects from the class my_class. You can create as many objects
from a class as you require. Once you create your objects then you can assign them to other
objects or even variables much the same way you do assignments for variables. But there
is a big difference between assignments of variables and assignments of objects. When you
assign objects then they are assigned using values. But when you assign objects they are as-
signed by reference. What it means is that when a variable is assigned a value then
Let us see some examples. First let us see things about instance variables.
Search WWH ::

Custom Search