Skip to content
March 20, 2013 / Danii Oliver

Constructor – Object Oriented Analysis and Design


Constructors initialize. You can have more than one constructor this is overloading the constructor.
class Inkjet {
public Inkjet(){…}

public Inkjet(int red, int blue, int green){…}

*with signatures the name of the arg fields is not important it is the type and order

If constructor is public…
Inkjet p = new Inkjet(); ← constructor must be public for this to work

If constructor is private, you can not instantiate the class from outside the class.
The class can only instantiate itself! → [see static Methods to make sense of this]

If the constructor is protected it means that it is expected to be instantiated in the subclass.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: