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

Robert Zaharia
PLUS
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 ?

...

com/example/BlogPost.java
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) {
    mAuthor=author;
    mTitle=title;
    mCategory=category;
    mBody=body;
    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.

Steve.

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!

Steve.