Constructor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaleeswaran
    New Member
    • Mar 2007
    • 132

    #1

    Constructor

    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?
  • prometheuzz
    Recognized Expert New Member
    • Apr 2007
    • 197

    #2
    Originally posted by kaleeswaran
    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.ht ml

    Good luck.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by kaleeswaran
      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

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by prometheuzz
        The use of constructors is explained thoroughly in this document:
        http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.ht ml

        Good luck.
        Hi Prometheuzz, what brought you here?

        kind regards,

        Jos

        Comment

        • prometheuzz
          Recognized Expert New Member
          • Apr 2007
          • 197

          #5
          Originally posted by JosAH
          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.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by prometheuzz
            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

            Comment

            Working...