Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8863405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:58:12+00:00 2026-06-14T15:58:12+00:00

In my driver program, this line gives me cannot find symbol error and I

  • 0

In my driver program, this line gives me cannot find symbol error and I don’t know why. The method is clearly defined in the SavingsAccount class, and I can refer to all other methods in my driver program but just not that one, I tried changing the type to double, and etc but still not working.

Account acct2 = new SavingsAccount (name);
acct2.calculateBalance();

SavingsAccount class inherits from Account class:

public class SavingsAccount extends Account
{
    private final short minBalance = 0;
    private double overdraftFee;
    private double yearlyInterestRate = 0.02;
    private double interestAmount;

    public SavingsAccount (String name)
    {
        super(name);
    }

    public double withdraw (double amount)
    {
        if (accountBalance - amount >= minBalance)
        {
            accountBalance -= amount;
            System.out.print ("Withdraw Successful");
        }
        else 
        {
            accountBalance -= amount;
            overdraftFee = accountBalance * (0.10);
            accountBalance += overdraftFee;
            System.out.print ("Withdraw Succesful, however overdraft fee of 10% has been applied to your account");


        }

        return accountBalance;
    }

// ----------------- this is the method I try to invoke -----------------------------
    public void calculateBalance ()
    {
        interestAmount = (accountBalance * yearlyInterestRate);
        accountBalance += interestAmount;
    }
// ----------------------------------------------------------------------------------

    public String toString()
    {
        return super.toString() + " Interest Received: " + interestAmount;
    }


}

Account class, if needed

import java.util.Random;
import java.text.NumberFormat;

public abstract class Account
{
    protected double accountBalance;
    protected long accountNumber;
    protected String accountHolder;
    public Account (String name)
    {
        accountHolder = name;
        accountBalance = 0;
        Random accountNo = new Random();
        accountNumber  = accountNo.nextInt(100000);
    }

    public double deposit (double amount)
    {
        accountBalance += amount;

        return accountBalance;
    }

    public String toString()
    {
        NumberFormat accountBal = NumberFormat.getCurrencyInstance();
        return "Account Balance: " + accountBal.format(accountBalance) + "\nAccount Number: " + accountNumber;
    }

    public String getAccountHolder()
    {
        return accountHolder;
    }

    public double getAccountBalance()
    {
        return accountBalance;
    }

    public abstract double withdraw (double amount);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:58:13+00:00Added an answer on June 14, 2026 at 3:58 pm
    Account acct2 = new SavingsAccount (name);
    acct2.calculateBalance();
    

    This is because although you have an object of SavingsAccount you are using refrence variable of type Account so you can access only those methods that are there in Account class.

    And you don’t have calculateBalance() method in your Account class.

    That’s why you are not able to access it and compiler complains that it cannot find a method named calculateBalance as it sees that reference type is Account and there is no such method inside Account class.

    If you want to use that method then change reference type to SavingsAccount :

    SavingsAccount acct2 = new SavingsAccount (name);
    

    Or you can explicitly cast it when accessing that method

    ((SavingsAccount) acct2).calculateBalance();
    

    but be alert that it can throw ClassCastException if acct2 object is actually not an object of SavingsAccount

    UPDATE:

    But
    remember that at runtime, Java uses virtual method invocation to dynamically
    select the actual version of the method that will run, based on the actual instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am new kernel programming.i have been trying to load this driver program for
i have this huge csv file, it's 4GB, don't know how many rows but
b.driver.manage.window.resize_to(1000, 1000) That line above doesn't work with chrome on my mac. I am
NetFoss requires you to run it with a command line similar to this: nf.bat
This is a simple program where i create two tables in a database using
I call my script like this: >Driver.exe 26268 01-01-2011 02-01-2011 arg 0 : c:\Services\JasperBatchService\Release\JasperBatchDriver.exe
I need to know if my program can write files to the disk (HDD,
I am using an example program from this code http://sicktoolbox.sourceforge.net/ > http://sourceforge.net/projects/sicktoolbox/files/ . It's
This might be in vain, as I know writing an operating system is unbearably
See, the problem is that I'm supposed to use an executable driver program (vdriver)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.