We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;classArithmetic{intadd(inta,intb){returna+b;}}classAdderextendsArithmetic{// No need to explicitly define the add method in Adder; it is inherited from Arithmetic}publicclassSolution{publicstaticvoidmain(String[]args){// Creating an instance of AdderAdderadder=newAdder();// Printing the superclass nameSystem.out.println("My superclass is: "+adder.getClass().getSuperclass().getName());// Testing the add methodintsum=adder.add(42,13);System.out.println("42 13 20");}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Inheritance II
You are viewing a single comment's thread. Return to all comments →