473,473 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Constructor

kaleeswaran
132 New Member
hi!!
i know only the meaning of constructor is "Class name is same as method name" apart from this what is the use of constructor.it creating instant object means where we can creat an object in the constructor class itself?
Apr 6 '07 #1
5 1481
prometheuzz
197 Recognized Expert New Member
hi!!
i know only the meaning of constructor is "Class name is same as method name" apart from this what is the use of constructor.it creating instant object means where we can creat an object in the constructor class itself?
The use of constructors is explained thoroughly in this document:
http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html

Good luck.
Apr 6 '07 #2
JosAH
11,448 Recognized Expert MVP
hi!!
i know only the meaning of constructor is "Class name is same as method name" apart from this what is the use of constructor.it creating instant object means where we can creat an object in the constructor class itself?
I'm afraid you don't really understand (yet) what Object Oriented programming
is all about. Here's an analogy:

Suppose I want furniture; being the lazy bum I am I simply go to a carpenter
and tell him/her: "make me a table". The carpenter: being a perfect craftsman
but with no memory at all, consults a little cabinet with a few recipes:

table: a rectangular plate of wood with four poles underneath, perpendicular
to the plate. The plate of wood should end up in a horizontal position.

chair: see table description but with one extra vertical plate of wood
mounted perpendicular to the table's suface; also a bit lower than a table.

couch: see chair description but quite a bit wider.


Those three recipes are the 'Constructors' for three things: tables, chairs and
couches. The carpenter is the 'new' operator who does what must be done:
building new things: there must be a recipe with the same title as the thing
to be created. The recipe itself tells how it should be created.The three
recipes are part of desciptions of what you can do with tables, chairs or
couches; they are the blueprints for the real things and are analogous to
classes.Note that a couch is a special kind of chair which in turn is a special
kind of table. Those are the rudiments of class inheritance.

kind regards,

Jos
Apr 6 '07 #3
JosAH
11,448 Recognized Expert MVP
The use of constructors is explained thoroughly in this document:
http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html

Good luck.
Hi Prometheuzz, what brought you here?

kind regards,

Jos
Apr 6 '07 #4
prometheuzz
197 Recognized Expert New Member
Hi Prometheuzz, what brought you here?

kind regards,

Jos
Well, you, of course! Your wife asked me to keep an eye on you and told me to remind you that you need to be home before 18:00 hrs!
; )

Seriously, I saw your post at SDN and was curious about this place. Read your article on sorting (nice, btw), but I'm more interested in your upcoming permutations article.
Apr 6 '07 #5
JosAH
11,448 Recognized Expert MVP
Well, you, of course! Your wife asked me to keep an eye on you and told me to remind you that you need to be home before 18:00 hrs!
; )
Well, tell her that I'm home already; in my back garden to be exact. (it's nice
and sunny overhere). None of the damage is my fault. ;-)

Seriously, I saw your post at SDN and was curious about this place. Read your article on sorting (nice, btw), but I'm more interested in your upcoming permutations article.
Ah, ok, got it. The permutation article is nothing much: it's going to permute
things without much hassle, no recursion needed and it can deal with non-
unique elements too. And a bit of math stuff at the end ;-)

kind regards,

Jos
Apr 6 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
23
by: Fabian Müller | last post by:
Hi all, my question is as follows: If have a class X and a class Y derived from X. Constructor of X is X(param1, param2) . Constructor of Y is Y(param1, ..., param4) .
12
by: Marcelo Pinto | last post by:
Hi all, In practice, what is the diference between a default constructor and an explicit default constructor? class Ai { public: Ai() {} };
18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
8
by: shuisheng | last post by:
Dear All, I am wondering how the default copy constructor of a derived class looks like. Does it look like class B : public A { B(const B& right) : A(right) {}
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
13
by: sam_cit | last post by:
Hi Everyone, I have the following unit to explain the problem that i have, class sample { public : sample() { printf("in sample...\n"); }
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.