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 trialPiril Okurogullari
39 PointsWhy do I get an error for the first line?
While compiling, I'm getting an error for the public class Intro line, but I couldn't realize why. Thanks
// I have setup a java.io.Console object for you named console
public class Intro {
public static void main(String[] args){
String firstName = "piril";
System.out.printf("My name is %s", firstName);
}
}
3 Answers
Mike Shertz
1,205 PointsHi Piril,
I just tried this out in the Workspace and I get the error "Name.java:1: error: class Intro is public, should be declared in a file named Intro.java
public class Intro {"
So it sounds like you need to either name your File "Intro.java" or name your class "Name". I tried with this change and the code runs properly.
Mike Shertz
1,205 PointsAh, maybe I wasn't specific enough, the line should read...
public class Name {
Don't include the quotes like it's a string
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsIn this challenge you don't need to define public class
.
Consider you are already inside public class {
, inside public static void main(String[] args)
.
Just type:
String firstName = "piril";
System.out.printf("My name is %s", firstName);
Piril Okurogullari
39 PointsThanks Alexander, it worked !
Piril Okurogullari
39 PointsPiril Okurogullari
39 PointsI tried to name my class "Name", but again it doesn't work. And the error is illegal start of expression for the first line.