FAQ: Learn Java: Methods - Reassigning Instance Fields


This community-built FAQ covers the “Reassigning Instance Fields” exercise from the lesson “Learn Java: Methods”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Reassigning Instance Fields

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


Ok, I’m getting “Non static variable price cannot be non-static variable price cannot be referenced from a static context

Error. I’ve obviously goofed something, but I can’t see what the goof is! HELP! (Be gentle, I’m sure it’s going to be something stupid, because I’m on caffeine and nervous energy with this exercise)

public class Store {
// instance fields
String productType;
double price;

// constructor method
public Store(String product, double initialPrice) {
productType = product;
price = initialPrice;

// increase price method
public void increasePrice(double priceToAdd){
double newPrice = price + priceToAdd;
double price = newPrice;

// main method
public static void main(String args) {
Store lemonadeStand = new Store(“Lemonade”, 3.75);


This is copy-paste from the lesson.

public static void main(String args){
SavingsAccount myAccount = new SavingsAccount(2000);

Could you please check if there this line is correct…
Shouldn’t it be: myAccount.deposit(100)?

tnx :slight_smile:

1 Like


try with
also in the last line of the main method

Br, M.


Came across the same thing, you can’t call SavingsAccount.deposit(100) in the same way that we can’t use Store.increasePrice(1.5), so I think that needs to be looked into


Hi adriennewrn,

The issue is when you created an object of the class Store i.e. “Store lemonadeStand = new Store(“Lemonade”, 3.75)” the name of the thing we need to call the “price” method on is “lemonadeStand”

Such that, what martinam080 said should fix the error as he is now (with dot notation) calling the “price” method on the variable lemonadeStand. It’s also worth noting that when you did create this object aka instance variable you declared with it, it’s type which in this case was Store. Thinking about it this way helps me so I thought it might help you too. In all variable declarations we always include the type whether that is “int,” “double,” “string,” or in this case “Store”

Hope that helps


Hey guys,

I use VSCode to do additional Java coding and sure enough when I tried to compile this code it produces that same error. So yup you guys are right. Needs to be changed to:


Most learners may not catch that, especially since you can’t run that code, unless the person is proficient enough to change the class name to match the name of the default folder that’s in the browser.