What is a Java Constructor?

In Java, a constructor defines the code that is run when a new object is created.

To create a constructor, define a block of code with the same name as the class. For example, the following defines the construtor for a class called “Painting”.

To invoke a constructor, use the “new” keyword, followed by the name of the class.

When creating a Java constructor, remember the Java Constructor Rules.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.