Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Objects (Retired) Harnessing the Power of Objects Methods and Constants

Paul Taylor
Paul Taylor
2,213 Points

method above constructor

Have a question? Wondering why it best for myself to add a method beneath the constructor and above it?

GoKart.java
public class GoKart {
  private String mColor;

  public GoKart(String color) {
    mColor = color;
  }

  public String getColor() {
    return mColor;
  } 
}

3 Answers

anil rahman
anil rahman
7,786 Points

It is usually just best practice that when a class is called it gets to the constructor first. So we end up following this rule of having constructor first then methods below that.

Paul Taylor
Paul Taylor
2,213 Points

So pretty much its just the way things operate, and thank you much.

anil rahman
anil rahman
7,786 Points

Yh pretty much just how it goes. People would expect to see a constructor first in your class code. :)