What is the purpose of "initialize"

G

Gaba Luschi

Why do you need initialize and what do you put in the parameter after
initialize(parameter)
?
 
B

Buddy Lindsey, Jr.

[Note: parts of this message were removed to make it a legal post.]

the initialize method is your constructor it is called when you create a new
object automatically. It doesn't have to take a parameter at all. If it does
then you can set that to an instance variable to use in that class. If you
didn't understand much of that you might want to pick up a book on object
oriented programming it explains in much more detail.
 
B

Brian Nicar

[Note: parts of this message were removed to make it a legal post.]

Well, it is called by default when one instantiates an object from a class.
Furthermore, a class need not require a parameter upon instantiation. As in,
object = MyClass.new will set up an object with default values you have
chosen in the 'initialize' method. Without 'initialize', you inherit the
base constructor from which all all classes are derived.
 
B

Brian Nicar

[Note: parts of this message were removed to make it a legal post.]

I should have said "from which all objects are derived"...

Well, it is called by default when one instantiates an object from a class.
Furthermore, a class need not require a parameter upon instantiation. As in,
object = MyClass.new will set up an object with default values you have
chosen in the 'initialize' method. Without 'initialize', you inherit the
base constructor from which all all classes are derived.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top