FAQ: Learn Java: Methods - Calling Methods

This community-built FAQ covers the “Calling Methods” 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 Calling Methods

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!

Can statements be printed out in other methods besides the main method?

// advertise method
  public void advertise() {
		System.out.println("Selling " + productType + "!");
    System.out.println("Come spend some money!");
  }
  
  // main method
  public static void main(String[] args) {
    Store lemonadeStand = new Store("Lemonade");
    lemonadeStand.advertise();
    lemonadeStand.advertise();
    lemonadeStand.advertise();
  }

If not, can the main method be written earlier in the code instead of last?

1 Like

The instructions for this section confused me a bit, because there was no lemonadeStand defined when it instructed me to call the advertise method on lemonadeStand. I believe the instructions should include a step to create the lemonadeStand object or it should already be apart of the boilerplate code to make it more clear for people who are just learning.

1 Like

This is a good solution.

public static void main(String args) {

Store lemonadeStand = new Store("Lemonade");

for (int i = 0; i < 4; i++ ){

lemonadeStand.advertise();

}

}

I encountered a bug, it seems

Did you ever get this figured out?

No, but somehow I managed to move to the next step (I don’t remember how). You can report a bug if you got that too. Press Get Unstuck → Bugs

I am still having this issue as of 4/17/23. You can move on by selecting replace with solution. Even though nothing appears to change other than letting you move on.

How is productType able to switch between 2 strings? you’re storing whatever store name you created when using the store method, but if you create 2 it’s somehow able to print out different productType ? if that makes sense.

When you create a new store using the method, it should switch productType to whatever you put in the args of new Store, but it just somehow is different for each store even though it’s one string?
so for example:

Store lemonadeStand = new Store(“Lemonade”);
Store bookStore = new Store(“Books”);
lemonadeStand.advertise();

since I created the bookStore last, the productType string should be “Books” but when I use the lemonade stand to advertise, it somehow prints out “Selling Lemonade!” still. how is it possible?