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