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

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top