I’m new at oop ,I want to pass object parameter of an abstract method but it gives me error, can anyone explain it to me and help me fix the error . Thanks for your help.
abstract class FunctionInt{ int num1; int num2; abstract FunctionInt test(FunctionInt newNum); } class Function extends FunctionInt{ public Function(int num1,int num2){ this.num1=num1; this.num2=num2; } public Function (){ } Function test(Function c){ return c; }
Advertisement
Answer
You cannot change the abstract method signature. You have created an entirely new method unrelated to the method you wanted to override. Use the @Override
annotation to spot this class of errors more quickly.
public class Function extends FunctionInt { public Function(int num1, int num2) { this.num1 = num1; this.num2 = num2; } public Function() { } @Override FunctionInt test(FunctionInt c) { return c; } }