FAQ: Learn Java: Methods - Defining Methods

#1

This community-built FAQ covers the “Defining 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 Defining 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!

#2

For this lesson(https://www.codecademy.com/courses/learn-java/lessons/learn-java-methods/exercises/defining-methods) that I am currently taking, the question says “In between the constructor and the main() method, add a method called advertise() to the Store class.”, but the advertise() isn’t actually in the Store class, but it is below it. May I know the reason why?

#3

We are instructed to write the method above the main() method. It will be a method of the Store class, will it not?

#4

Hello,

I was wondering as well for this problem of defining methods. The solution to the problem below is: public void advertise(){
System.out.println(“Come spend some money!”);
System.out.println("Selling " + productType + “!”);
My answer before is: public void advertise(){
System.out.println("Selling " + productType + “!”);
System.out.println(“Come spend some money!”);

if the order of the output reads: “Selling productType!”
" Come spend some money!"
Is my code correct why is the solution the reverse of these two ?
2.

Inside the advertise() method, type two print statements. They should result in the printouts:

“Selling productType!” “Come spend some money!”

where productType is replaced with the value in the variable productType .

However, we’re not going to see these Strings printed out yet! We’ll see in the next exercise how we can make these printouts actually run.