-4

I am trying to create a new constructor for the Monomial, but I keep getting the error

"return type is missing for coefficient"

Why is that so because constructors in java has no return type so why is the compiler is asking for a return type?

Additionally, how can I initialise private PolyNode monomilaist insider the constructor since it is private, and not public?

public class Polynomial implements CalculatorOperand<Polynomial> {


private class PolyNode {
    int coeff;
    int degree;
    PolyNode next;



    public Monomial(int coeff, int degree)
    {
        private PolyNode monomialsList; 
    }
Pushpesh Kumar Rajwanshi
  • 18,127
  • 2
  • 19
  • 36

1 Answers1

1

First a constructor needs to have the same name as the class.

Secondly a variable in a method may not have any modification like public, private or protected. It is only visible in the method anyway.

private class Monomial {
    int coeff;
    int degree;
    PolyNode next;



    public Monomial(int coeff, int degree)
    {
        PolyNode monomialsList; 
    }
michaeak
  • 1,548
  • 1
  • 12
  • 23
  • I revised my code. However, I am still getting the error that coeff and degree cannot be resolved to a variable. How can I fix this? `{ public class Polynomial implements CalculatorOperand { private class PolyNode { int coeff; int degree; PolyNode next; } Polynomial Monomial= new Polynomial(coeff, degree, null); private PolyNode monomialsList; }` – MunchiesOats Nov 12 '18 at 16:15
  • Well, I answered your question you put, I can not know whatever else is in your code. Open a new Question for new problems. – michaeak Nov 12 '18 at 16:51