Java Learning Note 2

Source: Internet
Author: User

In Java, the use of methods is in two steps:

1. Definition method

public void print () {   System.out.println ("Hello world!");}

Attention:

(1) The method body is placed in a pair of curly braces to achieve a specific operation

(2) The method name is mainly used when calling this method, we should pay attention to the naming of the normalization, generally we take the first word of the initial letter lowercase, the other Word capitalized form.

2. Call method

We define the method to invoke it to play its part, and when we need to invoke the method to perform an operation, we can first create the object of the class and then pass the

The name of the object. Method Name (), to implement a call to the method. Here's a demonstration:

public class helloworld{public   static void Main (string[] args) {   //create object whose name is HW   HelloWorld HW = new HelloWorld ();   Call the method Hw.print () that we defined above, in the form of the object name, method name ()   ;   }      Define method public   void print () {      System.out.println ("Hello world!");}   }

The result of the operation is: Hello world!

Java Learning Note 2

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.