Java Java Data Structures Getting There Packages

Bhawani Shankar
Bhawani Shankar
954 Points

Now in the main method of Display.java, instantiate a new BlogPost.

Now in the main method of Display.java, instantiate a new BlogPost. Use System.out.printf to print out "This is a blog post: %s" and pass in the newly created BlogPost object to replace the string formatter..

com/example/BlogPost.java
package com.example;
public class BlogPost(){
}
  public static void main (String[]args){
  }
Display.java
import com.example.blogPost;
public class Display {
  public static void main(String[] args) {
  BlogPost blogPost= new  BlogPost();
  System.out.printf("This is a blog post: %s %n",blogPost);

    // Your code here...
}

}

6 Answers

blogPost.java

package com.example;

public class BlogPost {

}

display.java

import com.example.BlogPost;
public class Display {
  public static void main(String[] args) {

    BlogPost myeBlog = new BlogPost();
    System.out.printf("This is a blog post: %s", myeBlog);

  }
}
Sean M
MOD
Sean M
Treehouse Moderator 7,330 Points

import com.example.BlogPost;

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

} }

i just tried it and it's working, just try copy everything and paste, I have no idea why is not working because here it does

Have you try replace your blogpost.java with this i sent you?

Fahad Mutair
Fahad Mutair
10,342 Points

you have syntax error with your import statement

Display.java
import com.example.blogPost;

change it to com.example.BlogPost

Fahad Mutair
Fahad Mutair
10,342 Points

also you don't have to type main method in BlogPost.java so remove this line

BlogPost.java
  public static void main (String[]args){
  }
Gonzalo Torres del Fierro
PRO
Gonzalo Torres del Fierro
Pro Student 16,740 Points

import com.example.BlogPost; public class Display { public static void main(String[] args) {

    BlogPost anyName = new BlogPost();
    System.out.printf("This is a blog post: %s", anyName);

} }

// remember to create a public class on the BlogPost file or the class will not be accessible!!