+ 1

What does super(<parameter>) means?

I solved this problem in a java course on overriding but I'm not sure what the code "super(amount)" does in this code below, an explanation would be very much appreciated Code: import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); double saving = read.nextDouble(); double checking = read.nextDouble(); Account savingAcc = new SavingAcc(saving); Account checkingAcc = new CheckingAcc(checking); System.out.println(savingAcc.getIncome()); System.out.println(checkingAcc.getIncome()); } } class Account { private double amount; public Account(double amount) { this.amount = amount; } public double getAmount() { return amount; } public double getIncome() { return 0; } } class SavingAcc extends Account { public SavingAcc(double amount) { super(amount); } //Override the method for saving account public double getIncome() { return getAmount() + getAmount()*0.2; } } class CheckingAcc extends Account { public CheckingAcc(double amount) { super(amount); } //Override the method for checking account public double getIncome() { return getAmount() + getAmount()*0.05; } }

8th Jan 2022, 7:06 AM
Yasa Wiharja
1 Answer
0
Super refers to parent class
8th Jan 2022, 9:25 AM
Dennis Torhov
Dennis Torhov - avatar