Java SE Nineth---Object-oriented feature encapsulation 1

Source: Internet
Author: User
Tags java se

1. Three basic features of object-oriented programming: Inheritance (inheritence), Encapsulation (encapsulation), polymorphism (polymorphism)

2. Encapsulation: Classes contain data and methods, and the data and methods in a class constitute the encapsulation

3. How to define a class:

The name of the Modifier class class

{

The contents of the class (including properties and methods)

}

4. Method: How to define a method

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

{

Method body

}

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

6. Method definitions cannot be nested, that is, methods cannot have methods, methods can only be defined in a class.

7. With respect to the execution of a method, you first need to define the method, and then you can use the method (the calling method), and when the method call is complete, the method can return a value that determines whether the value returned by the method is defined by its definition.

8. How do I generate an object? The object is generated by the class ( usually using the new keyword to generate the object).

Class Name Variable name = new class name ();

9. Method calls need to be done through an object, in the form of a method call:

Object variable. Method name ([parameter value 1, parameter value 2 ....] );

10. Notes on the methodology:

1) The return type of the method remains the same as the variable or constant type following return

2) in method invocation, the parameters passed to the method need to be consistent with the defined city parameters (two number of uniform parameters, parameter type)

3) method definition when the return type is consistent with the type of the Receive method return value

11.public int Add (int a,intb) {

return a+b;

}

The parameters of the method definition are called formal parameters (such as A and b)

int a= Test.add (8,3);

The actual arguments given when the method is called (such as 8,3)

12. Keyword void Definition method representation method does not return a value

13. If the method does not return a value, the Void keyword is used when declaring the method, and in the method definition, no return value can be implemented in two cases:

1) Do not use return statement

2) return is used, but there is no value or variable after return, there is only one semicolon after return, indicating the exit method, returned to the caller of the method

return using the method;

Java SE Nineth---Object-oriented feature encapsulation 1

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.