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 trialPratham Patel
4,976 PointsCan someone explain this code in a way I can put in a note
The code is Tower tower = new Tower(); Can you explain all of it This is in Object Oriented Programming in a video called initialization
1 Answer
Ryan Sheppard
2,866 PointsThis code creates a new Tower object and assigns it to a new variable named tower. This might look confusing now but eventually reading/writing statements like this becomes second-nature.
Here is a breakdown of the statement:
Tower // the new variable's Type
tower // the new variable's Name
= // the assignment operator
new Tower() // the instantiation (creation) of a new Tower object
; // the end of the statement