Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: John Cooper   on Feb 28 In Java Category.

  
Question Answered By: Bama Cohen   on Feb 28

yes one java  class can have more then one construtors
but atleast one constructor..
contructor is called when we create object of the
purticular classs..te first constructor  set the values
of the object instances ...for eg we crete a object of
the calss and set  the values the instances of the
object in the same step so we do this

public Die object1=new Die(); calling first
constructor over here after the caling this step the
values of

object1.myFaces=6 ///its set by the constructor
object1.faceValue=1 //its also set by construtor

the first contructor is zero paramiterize constructor
or default construtor
and the second constructor is parametrize constructor
its get the value from the user and then set it..

the name of the constructor is same the name of the
class wirh case sensitivity and contructors have no
return type..

Share: