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 trialBhawani Shankar
954 PointsNow 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..
package com.example;
public class BlogPost(){
}
public static void main (String[]args){
}
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
Ivan Bagaric
Courses Plus Student 12,356 PointsblogPost.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
7,344 Pointsimport 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);
} }
Ivan Bagaric
Courses Plus Student 12,356 Pointsi 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
Bhawani Shankar
954 PointsTHANK YOU SOO MUCH
Ivan Bagaric
Courses Plus Student 12,356 PointsHave you try replace your blogpost.java with this i sent you?
Bhawani Shankar
954 PointsYES BUT NOT WORKING
Fahad Mutair
10,359 Pointsyou have syntax error with your import statement
import com.example.blogPost;
change it to com.example.BlogPost
Bhawani Shankar
954 PointsNOT WORKING
Fahad Mutair
10,359 Pointsalso you don't have to type main method in BlogPost.java so remove this line
public static void main (String[]args){
}
Bhawani Shankar
954 PointsTHANK YOU SOO MUCH
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Pointsimport 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!!
Bhawani Shankar
954 PointsBhawani Shankar
954 PointsNot working