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 trialxander de los Santos
Courses Plus Student 1,191 Pointshow do I make an object?
i just can't figure out how.....
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
1 Answer
Sidney Casagrande
7,035 PointsIn Java just about everything is an Object. If you look at http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html it states:
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
Now knowing that Object is a java class you can assume that it's got a constructor. If you look back in the doc you can find public Object(). Now to create something from a constructor works this way:
TypeOfClass myVariableName = new ConstructorOfClass();
Give it a try and let me know if you managed to create an Object called obj which instantiates a new Object()...
xander de los Santos
Courses Plus Student 1,191 Pointsxander de los Santos
Courses Plus Student 1,191 PointsThanks... That helped a lot...