Advantages of Constructor Overloading

前端 未结 6 1857
青春惊慌失措
青春惊慌失措 2021-01-18 10:45

I am very new to Java and trying to learn the subject, having previous programming exposure in only HTML/CSS. I have started with Herbert Schildt and progressed through a fe

6条回答
  •  死守一世寂寞
    2021-01-18 11:41

    You may have several variables in a class... But you want to initialize only few(one or two) variables at the time of object creation. So in this case Its always better to have overloaded constructors so that you can call respective constructor depends on your requirement. One thing you should remember always,.. while overloading constructors always provide a default constructor(Zero argument constructor).Even with empty implementation.

提交回复
热议问题