this - What's the difference between these two constructors in java ? (Memory) -


here in code

public class base {     int length, breadth, height;      base(int l, int b, int h) {         length = l;         breadth = b;         height = h;     } } 

and

base(int l, int b, int h) {     this.length = l;     this.breadth = b;     this.height = h; } 

here what's difference between 2 constructors intialization? method highly preferred? how varies in terms of memory allocation?

there's no difference. in first constructor omit this while in second explicitly specify it. generated bytecode same (you can check it). it's matter of style if want put or not, unless field has same name parameter, in case this mandatory avoid ambiguity, example:

base(int length,int breadth,int height) {    this.length = length;    this.breadth = breadth;    this.height = height; } 

(please use spaces wisely, makes code more readable).


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -