here is the sample code
public class BankAccount {
protected double getBalance() {return 1000.0;}
}
package test;
public class SavingAccount extends BankAccount{
protected double getBalance() {return 1010.0;}
protected void printBalance() {
System.out.println(super.getBalance());
System.out.println(getBalance());
System.out.println(this.getBalance());
}
}
Super.getBalance() returns the value of the parent class, so it is 1000.0 this.getBalace() returns the value of the current object, so it is 1010.0 but I am not sure how getBalance() works. shouldn't it be the same as this.getBalance()? also how do I run it to see the result? I am using eclipse. Didn't find out how to run it without a main. and can't just creat a main like
public void main (String[] args) {
SavingAccount.printBalance();
}
because "Cannot make a static reference to the non-static method printBalance() from the type SavingAccount"