I'm trying to override equals method, but I'm getting error
I have two classes one abstract and the inherited class.
public abstract class MyData extends Object
{
public abstract boolean equals(MyData ohtherData);
}
public class IntData extends MyData
{
protected int num;
public IntData (int n)
{
this.num = n;
}
public boolean setNum(int n)
{
if (n<0)
return false;
else
{
this.num = n;
return true;
}
}
@Override
public boolean equals(MyData otherData)
{
if (otherData == null || this.getClass() != otherData.getClass())
return false;
else
{
MyData newData = (MyData) otherData;
return this.num = newData.num;
}
}
}
I have problem with the last line return this.num = newData.num;
I'm getting that num for newData can not be resolved or is not a field. Nevetherless, my teacher said that I CAN NOT put protected int num in the abstract class. My teacher checked my code and said that it should work but it doesn't.
Any help would be appreciated.