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 Data Structures Getting There Class Review

Robert Zaharia
Robert Zaharia
Courses Plus Student 579 Points

Hi ! I have to add a getter method for body and it seems like i have compilation error. Can u please help me ?


package com.example;
import java.util.Date;

public class BlogPost {
  private String mAuthor;
  private String mTitle;
  private String mCategory;
  private String mBody;
  private  Date mCreationDate;

  public BlogPost(String author, String title, String category, String body, Date creationDate) {
    mCreationDate = creationDate;}}
public String getBody(){
      return mBody; }

1 Answer

Hi Robert,

You've closed the class after the constructor; there is one too many closing curly braces. Remove one of those closing braces and move it to after the getter method.


I'd suggest being disciplined on using new lines for your braces. That way, you can keep track of your indentation.

package // packages
import // imports

public class BlogPost{
  private String mVariable;

  public BlogPost(String variable){
    this.mVariable = variable;

  public String getVariable(){
    return mVariable;

Just an example class to demonstrate good indentation. It is easier to keep track of braces this way. I hope there's no typos!