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 trialAndre Kucharzyk
4,479 PointsWhy someStuff[0] instanceof Treet = true ?
import com.teamtreehouse.Treet;
import java.util.Date;
Treet treet = new Treet("Sam Harris", "awesome stuff",
new Date());
Object obj = treet; <--- treet changed to object!!!
Object[] someStuff = {treet, "a string"};
someStuff[0] instanceof Treet;
Why the outcome of someStuff[0] instanceof Treet = true ??? Wasn't treet changed to Object??
Please somebody give me a hand.
1 Answer
adsdev
15,583 PointsHi Andre Kucharzyk ,
You assigned the treet object to the obj variable. This means that obj now "contains" the treet variable. The treet variable is an instance of the Treet class. So when you call the instanceof method on object, containing the treet object variable which again is of the type Treet, checks if it is indeed an instance of Treet. And since it does, it values to true.
Bogdan Siverchuk
Courses Plus Student 1,707 PointsBogdan Siverchuk
Courses Plus Student 1,707 PointsI might be wrong but array starts with 0 and treet is the first one so it is 0. And it is not changed just equals to treet.