forum

Home / DeveloperSection / Forums / New Object is overriding another Object variable

New Object is overriding another Object variable

Royce Roy 1355 27-Dec-2015
I have created two Function objects, the values in the first get overwritten with the values assigned to the second object.
What is wrong in this approch?

public class Function { 
private static double coefficient;
private static int startX;
private static int endX;
private static int exponent;

protected Function(double coefficient, int startX, int endX, int exponent) {
    this.coefficient = coefficient;
    this.startX = startX;
    this.endX = endX;
    this.exponent = exponent;
  }  
    public static void main(String[] args) {
    Function func1 = new Function(2, 1, 2, 2); 
    Function func2 = new Function(0,1,2,1/3);
    // now func1 properties are the same as func2
      } 
   }
}

java java  oops 
Updated on 27-Dec-2015

Can you answer this question?


Answer

1 Answers

Liked By