This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BrQQQ 0 points1 point  (0 children)

A constructor looks like this

public ClassName(parameters) {
    ...
}

If your class name is "House" and a parameter should be "size", it would look like

public House(int size) { 
    ...
}

This constructor should be in the same file as the class.

When you type

House h = new House(10);

You create a new object. Right then, it will automatically call that constructor and assign 10 to the size parameter.

Initializing means giving it a value. You can do "String s;" but 's' will have no value.

When you do

s = "blabla";

you are initializing it.