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

Java

java

What id the difference between those two things?

Game game = new Game(); private Game game;

2 Answers

Game game = new Game(); // u construct a class
private/*type of access*/ Game /*class of variable*/ game /*variable name*/; 
  1. Type of access (private/public/protected) - https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
  2. Type of variable - https://www.tutorialspoint.com/java/java_variable_types.htm
  3. Variable name of type Game. - https://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html
  4. class construction - https://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html

Hope that helps

Game game = new Game() is constructing a new instance of the Game class which will be referenced by the variable name: game.

private Game game looks like a declaration of an instance variable of the type Game which has been set to private access.