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 trialKlaudia Krol
576 Pointscreating new objects JAVA - 1st and 2nd challenge
Hi All ,
I have roblems to understand objects , Could you please help out how this code should look like and maybe useful comments ?
Thanks in advance , Klaudia
public class Example {
public static void main(String[] args) {
System.out.println("We are going to create a GoKart");
}
}
2 Answers
Shane Robinson
7,324 PointsJava objects are a very important concept to understand, I would recommend going back and re-watching the videos to get a better grasp of it. Also, go Googling to get a deeper understanding, if necessary, there are many tutorials like this one that could help you with your understanding.
Steve Fielding
7,287 PointsHi Klaudia. Just as Shane said, objects are very important concepts in Java. We create a new Object in java with the "new" Keyword. This is used to invokes a new Constructor Object like this... Dog dog = new Dog(); . Here "dog" becomes a new reference variable, which can be used to call any method in the Constructor class like this dog.buck(); . Assuming buck is a method in the Dog class. The example you have above is public static void main(String[] args) {} is called when you want to execute a java program. Public means main() method can be called from everywhere Static means main does not belong to a specific object void means main does not return a value Main() is a special function that is used to start a program. String[] is an array of arrays That said you can not create a new Object from a static method. You can only create a new Object from a non static or non Final class, an instance method, and so on. Some Access Modifiers and the Final Keyword prevents new Objects from being created. You can find more help on stack overflow http://stackoverflow.com/questions/2350552/creating-objects-in-java-question