Results 1 to 3 of 3
  1. #1
    random0munky is offline Member
    Join Date
    Oct 2008
    Location
    Washington, US
    Posts
    28
    Rep Power
    0

    Default Trying to initialize variables

    Hi, I'm having a little trouble with the introduction of the final modifier. I'm doing a bankAccount homework assignment, however I ran into my first problem.
    Java Code:
    public class BankAccount implements NamedAccount {
    	
    	private String name ;
    	private double iRate ;
    	private double balance ;
    	
    public BankAccount(final String nameOfOwner, final double interestRate) {
    	
    }
    What I want to do is take nameOfOwner = name ; and interestRate = iRate ;
    Except there's the final modifier in front of nameOfOwner and interestRate. Also I cannot change the method signature in anyway either.
    So my question is, how do i do such a task =/ Thanks

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    You can't change the values of final variables once they are assigned. That is where they get get their name (final) from. You probably don't want to do nameOfOwner = name but name = nameOfOwner instead. The two are different.
    Last edited by r035198x; 10-14-2009 at 10:31 PM.

  3. #3
    random0munky is offline Member
    Join Date
    Oct 2008
    Location
    Washington, US
    Posts
    28
    Rep Power
    0

    Default

    Ah great thank you oh my gosh I was beating my head (why isn't this working) thanks.

Similar Threads

  1. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  2. ObjectInputStream does not initialize
    By Singing Boyo in forum New To Java
    Replies: 1
    Last Post: 06-03-2009, 08:11 AM
  3. How to initialize an Array
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:47 PM
  4. Initialize variables before use
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-22-2007, 12:22 PM
  5. I do not know how to initialize the two variables
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •