views:

49

answers:

4

So say I have this class:

public class PositionList {
    private Position[] data = new Position[0];
    private int size = 0;

Now lets say I create a new PositionList object with the default constructor, so no arguments like so:

PositionList list = new PositionList();

Does the new list object have any attributes? Does it have a size component or a data component? What are its characteristics?

A: 

It has private data and size fields, but you can't access those from outside the class. Anything public will be accessible.

alpha123
+1  A: 

Yes, it will use your initializers. So the size will be zero (it's default value, so your setting it to 0 is redundant) and data will be an array with 0 elements (distinct from null).

Kirk Woll
Oh ok. On a related note, can you help with this:http://stackoverflow.com/questions/3946668/copying-an-object-using-a-constructor-java
fprime
A: 

Yes, it has members data and size, and they take up space. When you construct an object with the default ctor, all the members are constructed using their default ctors.

Charlie Martin
A: 

Prior to any constructor call (default or otherwise), all of your object's instance variables (e.g. data and size) will be initialized to their default values. For objects and arrays this is null, for numeric types it's 0 or 0.0, for boolean types it's false.

petref4x