0

why constructor call must be the first statement in a constructor?

please explain this

14th Sep 2016, 11:53 AM
Pradeep Saini
Pradeep Saini - avatar
2 Antworten
0
Can you give more details..Do you mean why calling costructor inside main class before accessing the object methods
14th Sep 2016, 1:51 PM
Tiger
Tiger - avatar
0
actually he is asking in programming while we using this key word or super key word to invoke other constructor we must call it as first statement. ex: public Rectangle() { this(0,0,1,1); // statements } public Rectangle( int x,int y,int width,int height) { this.x=x; this.y=y; this.width=width; this.height=height} in the above ex Rectangle() method invokes other constructor i.e parameterized rectangle constructor
14th Sep 2016, 2:28 PM
Teja Naraharisetti
Teja Naraharisetti - avatar