Java Object-oriented encapsulation

Source: Internet
Author: User

    1. Three basic features of object-oriented programs: inheritance, encapsulation, polymorphism

    2. Encapsulation: Classes contain data and methods, and putting data and methods in one class constitutes the encapsulation

    3. How do I define a class?

      The name of the Modifier class class {


      The contents of the class (including properties and methods)


      }

    4. method, how to define the method?

      Modifier returns a value type method name ([parameter 1, Parameter 2, Parameter 3 ...] ){


      Method body

      }

    5. The Main method is the entry point for the entire Java program, and if there is no main method in the definition of the class, there is no way for the program to execute

    6. A method definition cannot be nested, and another method cannot be nested within a method, and the method can only be defined in a class.

    7. As for the execution of a method, you first need to define the method, and then you can use the method (calling method) when

      After the call is complete, the method can return a value that determines whether the method returns the value that is defined by the method

    8. How do I generate an object? Using classes to build objects (usually using the new keyword to generate objects)

      public class person{




}

Class Name Variable name = new class name ();

person person = new person ();

9. Method calls need to be done by object to complete the method call in the form of:

Object variable. Method name (parameter value 1, parameter value 2, parameter value 3 ....) )

10. Notes on the methodology:

1. In the method definition, the return type of the method is consistent with the variable or constant following return

2. When a method is called, the parameters passed to the method need to be consistent with the parameters of the method definition (the number of parameters is the same as the parameter type)

3. The return type at the time of the method definition is consistent with the type of the Receive method return worthwhile variable

public int Add (int a, int b) {

return a + B;

}

int a = Test.add (x, y);

Parameters called formal parameters at the time of method invocation

The method called by the method is called the actual parameter.

System.out.println (a);

11. Key void indicates that the method does not return a value

12. If the method does not return a value, the Void keyword is used when declaring the method, and there can be two cases in the method definition that do not return a value

A. Not applicable return statement

B. Use return, but the return is followed by any variable, return followed by a semicolon, indicating the exit method, return method call end

This article is from the "Shang Build" blog, please make sure to keep this source http://hnyuanzijian.blog.51cto.com/8869344/1773604

Java Object-oriented encapsulation

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.