Java Java Data Structures Getting There Packages

Quinn Manning
Quinn Manning
3,045 Points

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,769 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.

Quinn Manning
Quinn Manning
3,045 Points

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,769 Points

You are welcome, glad I could help.