473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problems Understanding Constructors

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
2 1904
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
1
by: Antuane | last post by:
I've got a class as follows, PUBLIC CLASS BaseClass Sub New() End Sub Sub New(byval cName as String) End Sub
2
by: Mike | last post by:
Hey guys, need some help understanding some things that maybe someone can explain or clarify it a little better then a text book. Here is my understanding so far: Class - basically a shell for...
5
by: jose luis fernandez diaz | last post by:
Hi, When I compiling the program below: #include <map> using namespace std; template<typename td1, typename td2, typename td3,typename td4> class Tarificador
1
by: Brett Baisley | last post by:
I got an example that works at school, and it should work here as well. The problem I think is that VS.net won't allow multiple constructors. Here are the 3 errors I get: 1. warning C4521:...
6
by: Stephen Martinelli | last post by:
thanks for the help...just one more question.... can a class have more then two parameterized constructors?..i would like to be able to instanciate the class with a different number of...
3
by: John | last post by:
Before anything else, thanks Marina, Workgroups and Ralf, for your help so far. I am now able to better define the question! After adding more console printout lines to CSum, I tried all...
18
by: __PPS__ | last post by:
Hello, I'm a university student and I'm preparing for my final today. I'm reading course notes, I found completely strange piece of code. It makes me laugh, I think the teacher needs to prepare...
0
by: Dijkstra | last post by:
Hi! I am writing a program in which I need to keep track of how many objects of a given class exists at a time. The task is to do it using templates. The objects to be counted are of the class Note:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.