Declaring Objects Assignment Help

Assignment Help: >> Classes and Objects in Java - Declaring Objects

Declaring Objects

As just earlier, when you create a class, you are actually creating a new data type. You can use this type to declare objects of that type. Moreover, getting objects of a class is a two step procedure. First you must have declared a variable of the class type. That variable does not define an object. Alternatively, it is simply a variable which can refer to an object. Second, you must obtain an actual, physical copy of the object and assign it to that particular variable. You could do this using the new operator. A new operator is dynamically allocates (which is allocates at run time) memory for an objects and return a reference to it. This reference is less or more, an address in memory of the object allocated through new. This reference is then stored in the variable. Therefore in Java all class objects have to be dynamically allocated. Now let's look at the details of this procedure.

Box mybox = new box ( );

This statement merges the two steps just described. It can be rewritten like this to display each step more clearly;

Box mybox ;  / / declare reference to object

Mybox = new Box } ( ) ; allocate a Box object

The effect of those two lines of code is depicted in the given figure

210_declaring objects.png

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd