Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Meet Objects Creating New Objects

Klaudia Krol
Klaudia Krol
576 Points

creating 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

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
    }
}

2 Answers

Java 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
Steve Fielding
7,287 Points

Hi 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