• Post Reply Bookmark Topic Watch Topic
  • New Topic

Constructers  RSS feed

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we need constructers?
 
Bartender
Posts: 2273
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, otherwise, how would we be able to instantiate objects? Providing Constructors for Your Classes.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

Constructors has the same name as the class name.
Constructors are used for allocating memory space for variables.
Its include parameter and Its invoked by new operator.
Constructors have no return type.
If there is no constructor in your class, default constructor automatically created.

For more programming in constructor try this links,
http://www.javabeginner.com/learn-java/java-constructors

thanks
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we need constructers?


It's constructors.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything like destructer in java?
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. You never know when an object will be destroyed. It is totally depends upon garbage collection. Therefore no Destructors in java.
 
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to google for 'finalize()' method. It is the closest thing to destructors that Java has got. Of course, it has its limitations, so it is strongly advised that you read about it well, before attempting to rely on it.
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aditya Jha wrote: . . . 'finalize()' . . . has its limitations . . .
Very wise warning There is a section about it in Effective Java by Joshua Bloch, which you might be able to find as a sample chapter free of charge on the net (old edition).
Bloch recommends using finalize() only for cleaning up native resources, ie those written in C/C++ or other non-Java™ languages.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!