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 Packages

Cant get this to compile and dont understand why it wont.

Am I missing some simple syntax thing here? I dont understand why this doesnt pass. All it is supposed to do is print out the newly created object bp.

com/example/BlogPost.java
package com.example;

public class BlogPost {

}
Display.java
import com.example.BlogPost;

public class Display {
  public static void main(String[] args) {
    // Your code here...
    BlogPost bp = new BlogPost() {
      System.out.printf("This is a blog post: %s", bp);
    }
  }
}

2 Answers

Boban Talevski
Boban Talevski
24,793 Points

Your code at this point should look like this:

import com.example.BlogPost;

public class Display {
  public static void main(String[] args) {
    // Your code here...
    BlogPost blogPost = new BlogPost(); // this is instantiating an object of the BlogPost class
    System.out.printf("This is a blog post: %s", blogPost); // And this is the line that prints it

  }
}

The above two statements should be separate, so that creating an object ends with a semicolon and then the other line prints that object using System.out.printf. That statement also ends with a semicolon.

What you have done is trying to create an anonymous inner class BlogPost which is a more advanced topic covered in later courses.

Thats it thank you! I swear after doing these courses for a few hours it all blends together and I cant spot even the most basic of syntactical issues. Very much appreciated.

Boban Talevski
Boban Talevski
24,793 Points

You are welcome, glad I could help.