Saturday 15 March 2014

Constructor Overflow Java -



Constructor Overflow Java -

this question has reply here:

what's wrong overridable method calls in constructors? 5 answers

here code part of program. i'm concerned of constructor override warning addtotalperimeter. other parts of programme not of import have been left out. can prepare constructor override?

public triangle(int side_a,int side_b,int side_c){ if(isvalid() == true) { this.side_a = side_a; this.side_b = side_b; this.side_c = side_c; accumulator = addtotalperim(); } else { this.side_a = 1; this.side_b = 1; this.side_c = 1; } counter++; } private boolean isvalid(){ int x = 6; int y = 5; if(side_a > 0 && side_b > 0 && side_c > 0){ y = 1; } if((side_a + side_b > side_c) && (side_a + side_c > side_b) && (side_b + side_c > side_a)){ x = 1; } if(x == y) homecoming true; else homecoming false; } public int addtotalperim(){ accumulator += calcperim(); homecoming accumulator += calcperim(); }

what describe isn't overriding. if don't specify default constructor, compiler create default constructor. if it's subclass, phone call default parent constructor(super()), initialize instance variables default value determined type's default value(0 numeric types, false booleans, or null objects).

overriding happens when subclass has same name, number/type of parameters, , same homecoming type instance method of superclass. in case, subclass override superclass's method.

java constructor

No comments:

Post a Comment