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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -