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
naga bonar3,338 Points
why does the console object here did not use "new"?
May somebody help me explain why does the console object in the promptForGuess method did not use "new"? Why does it use static method directly?
We don't use
new because it already exists.
System.console() as a program/app on Windows or Mac.
Console console= is essentially creating a shortcut (Windows) or alias (Mac) for the program/app (in this case, the program/app is our console that we write commands in and receive feedback in).
Essentially it's a nickname to refer to the object, not the object itself. It's a bit easier to read and type if you call it "console" instead of "System.console" all the time. And we DON'T want to create a new program/app because we can only see one console at a time--the one that's already created.