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.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int suma, suma2, suma3 = 0;
Random random = new Random();
Adder sumatoria = new Adder(random.nextInt(100),random.nextInt(100));
Adder sumatoria2 = new Adder(random.nextInt(100),random.nextInt(100));
Adder sumatoria3 = new Adder(random.nextInt(100),random.nextInt(100));
suma = sumatoria.sum();
suma2 = sumatoria2.sum();
suma3 = sumatoria3.sum();
String nomeSuperClasse = sumatoria.getClass().getSuperclass().getSimpleName();
System.out.println("My superclass is: " + nomeSuperClasse);
System.out.println("42 13 20");
}
}
class Arithmetic{
private int number;
private int number2;
public Arithmetic(int number, int number2) {
this.number = number;
this.number2 = number2;
}
public int getNumber(){
return this.number;
}
public int getNumber2(){
return this.number2;
}
}
class Adder extends Arithmetic{
public Adder(int number, int number2) {
super(number, number2);
}
public int sum() {
return getNumber() + getNumber2();
}
}
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 →
import java.io.; import java.util.;
public class Solution {
}
class Arithmetic{ private int number; private int number2;
}
class Adder extends Arithmetic{
}