By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

Problems Understanding Constructors

P: n/a
Could someone give me a good definition and an example of a constructor?
I'm having problems trying to understand it. I thought it was just a way to
initialize variables in a class but I guess it does much more than that.
Any websites that might help would be appreciated.
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Shadowplay wrote:
Could someone give me a good definition and an example of a constructor?
I'm having problems trying to understand it. I thought it was just a way to
initialize variables in a class but I guess it does much more than that.
Any websites that might help would be appreciated.


Hm, maybe you should consider buying a good book about java. (Or even
another programming language)

A constructor is a method with the same name as the class and is invoked
at the moment a new object is created.

But indeed there is more about it. Get some good books (either in
electronic form or on paper)

Maybe just hang around in one of the bigger bookshops in a big town
(+500.000 citizens).

Go, read :-)
Jul 17 '05 #2

P: n/a
"Shadowplay" <An*************@hugeass.com> wrote in message news:<Wb********************@comcast.com>...
Could someone give me a good definition and an example of a constructor?
I'm having problems trying to understand it. I thought it was just a way to
initialize variables in a class but I guess it does much more than that.
Any websites that might help would be appreciated. initialize variables in a class

variables in an object

In the beginning you load class onto JVM memory. There's no object at
that moment. Then a static method in the class, typically main()
method, creates an object of the class or of some other class by
calling:

Foo f = new Foo();

This 'new' operator calls constructor of the Foo class. If you don't
write any constructor for your class, Java provides minimum barebone
one automatically.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.