public void differs from public static void in Java

Source: Internet
Author: User

The static method can be called directly by the Main method, not the static method.
Because the static method belongs to a class, it is a class method. Can be called directly through the class name. Method Name.
Instead of the static method, it must wait until the object is new to be used, so it cannot be called directly in Main.

The public void modifier is a non-static method that belongs to an object and can be called after object initialization (new object ()).
public static void decoration is a static method that belongs to a class and is called directly using the class name. Method Name.

Java can call static methods (object names. static methods) through the object name. There is no syntax error in Java (syntax error), but this is not recommended, and static methods should be absolutely differentiated from non-static method invocations, and other OOP languages such as c#,swift,objective-c do not have such syntax.

public void differs from public static void in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.