javaoopobject-oriented-analysis

Java OOP concept


public class MyClass {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

From the above, if we say that MyClass is the class and public static void main(String[] args) is the method, then I would like to know what part of the code would be considered as the Object.

If we say that classes have objects and objects have methods, then in the code above, which part is the object? Is there any object created here?


Solution

  • static methods don't belong to object references but to classes instead. You can execute a static method without creating an instance of the class. Knowing this, the only object references that would be created here would be:

    Note that args and its contents aren't created by you, the JVM will do it (thanks to Thilo's comment).