Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructurs advanteges..

 
Anas El-Abboud
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends..
plz, wt the most importance advantage from "constructure" ,
i donn't know else that i can pass the values for the class by it ,
but when i must write the programming inside the constructure & y ?
thanks.
 
Manoj Zachariah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in short : constructer are the first method that will be called when an object of that class is initialized. so its a good idea to put all variable initialization over there.
get more details from www.java.sun.com
 
Anas El-Abboud
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep, thanks Manoj.. it was usefull link , by constructur details and some other information..
but whould you give an exampple about i put the programing "not the init" in that method "Constructur" !
coz all the programs which i saw them were include the init only !
thanks.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet and Applet classes might contain init methods which are automatically invoked by the container in which they run. This method is a good place to put code that needs to be run on the creation and initialization of an Applet or a Servlet.
Since a constructor is going to be used to create an instance of the Servlet or Applet as appropriate, it would also work to place code that needs to be run at the creation of the Servlet or Applet in that code block.
Note that in Java a constructor is not a method. A method is a member of something - it's a member of a class in the case of static methods, or a member of an object in the case of instance methods. Constructors aren't members of anything. Methods return values - sometimes void. Constructors cannot return anything. Methods can be inherited. Constructors are never inherited. Some other languages do use the term constructor method when referring to what must be a similar construct as a constructor in Java, but in Java they're just called constructors.
 
Anas El-Abboud
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks v. much friend Dirk..
it is really the best board for jave i ever seen..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic