In this HackerRank Java Inheritance II problem, we need to write a class named Arithmetic with a method named add that takes 2 integers as parameters and returns an integer denoting their sum. a class named Adder that inherits from a superclass named Arithmetic.

HackerRank Java Inheritance II problem solution

HackerRank Java Inheritance II problem solution

//Write your code here
abstract class Arithmatic{
    public abstract int add(final int a, final int b);
}

public class Adder extends Arithmatic{
    @Override
    public int add(final int a, final int b){
        return a + b;
    }
    
    public static void main(String[] args){
        Adder X=new Adder();
        System.out.println("My superclass is: "+X.getClass().getSuperclass().getName());    
        System.out.print(X.add(10,32)+" "+X.add(10,3)+" "+X.add(10,10)+"\n");
    }
}