0

Can somebody please tell me why this code does not have an output?

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); amount+=amount*0.2; } //Override the method for saving account public double getIncome() { // amount +=amount*0.2; return amount; } }

2nd Nov 2021, 1:23 AM
Samir Krasnic
Samir Krasnic - avatar
1 Answer
+ 2
I fixed your code, and I mentioned the changes in comments. Mostly it's some bracing mistake. And you tried to access a private variable of the base class in derived class, so I changed the access specifier to protected. All the best =) https://code.sololearn.com/c2jXMEs2n47j/?ref=app
2nd Nov 2021, 1:36 AM
Rishi
Rishi - avatar