Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: John Cooper   on Feb 28 In Java Category.

  
Question Answered By: Dale Jones   on Feb 28

Constructors r been used to execute the code  that have to b executed as soon as
the object is been created or instansiated.



So the Die constructor  is called when we create an object

public Die ()
{
numFaces = 6;
faceValue = 1;
}


ie Die d =new Die();


The second constructor the below one is called when i created an object this way
Die d=new Die(12);

public Die (int faces)
{
if (faces < MIN_FACES)
numFaces = 6;
else
numFaces = faces;

faceValue = 1;
}

Share: