Non-parametric method of class

Source: Internet
Author: User
Tags getcolor

1. Two main characteristics of an object: properties and methods.

2. Method: The Access modifier method returns a value type method name () {

The body of the method

3. No parameter method:

(1) There is a return value

For example: Public String play () {

The type of the return value is consistent with the return value type of the method

return "hehe";

(2) No return value

For example: public void play () {

4. With the parameter method: Mutual invocation is allowed between methods.

5. member variables and local variables:

(1) A member variable refers to a variable in a class

Can be used anywhere in the class! Java gives the member variable an initial value.

(2) A local variable refers to a variable in a method

Can only be used inside the method, out of the way is not in! Java does not assign an initial value to a local variable.

In the same class, a local variable has a higher precedence when the member variable has the same name as a local variable.

3.JavaDoc

Start with "/**" and End With "*\".

Electric Lion Category:
Public classautolion{String Color= "Yellow"; Color
/* Run * / Public voidrun () {System.out.println ("Running forward at 0.1 m/s.");}
/* Snatch Ball */publlic string Robball () {string ball= "Ball"; returnBall;}
/* Get color * / PublicString GetColor () {returncolor;}
/* Show Lion's features * / PublicString showlion () {return"This is a" +getcolor () + "Toy Lion!";}

Test class:
publicclass testlion{ publicstaticvoid main (string[] args); =new autolion (); Create Autolion object String Info=lion.showlion ();    Call the method and receive the return value of the method System.out.println (info);            Display class Information lion.run (); Call the way to run System.out.println ("Grab a" + Lion.robball ();)//Call the ball method

Non-parametric method of class

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.