37- serialized Java object oriented encapsulation

First, new construction continues on IDE

1. In the src directory new packages: package mechanism behind repeat that, currently first with the

2. Name a name to the package: com.bjpowernode.java_learning

3. Create a new class under package

4. The package is part of Java syntax, followed by repeat

Object oriented encapsulation

Second, shortcut keys

CTRL + D: delete a row

ALT + /: auto-complete

CTRL + ALT + Down arrow: Copy line

Note: the contents of the IDE is not saved are not compiled, so to save time

autocomplete main method: input main, and CTRL + / main method will autocomplete

Third, the object-oriented encapsulation

1. Packaging benefits:

After (1) package for that thing is, do not see the things that side of the complex, only able to see the simple things of that side. The complexity of the package, providing simple operation outside the entrance, the camera is a good package case, realization of the principle of the camera is very complex. TV internal implementation is very complex, but for the user does not need to be concerned about the internal implementation principle, will only need to operate the remote control on it.

(2) will be formed after packaging real "object" real "independent body"

(3) on the package means that future programs can be reused, and this thing should be relatively strong adaptability, can be used on any occasion.

example:

The following User class we can directly access its information age

A User object represents a user, the user's age can not be negative, the following procedures in the age value is negative, while the program is running and there is no error, this is the current defect program

 

package com.bjpowernode.java_learning;


public class D37_encapsulation {


  public static void main(String[] args) {

    // TODO Auto-generated method stub

    User user = new User();

    user.age = -5;

    System.out.println(user.age);   

  } 

}

class User{

  String name;

  int age;

}

Fourth, the source code:

D37_encapsulation.java

address:

https://github.com/ruigege66/Java/blob/master/D37_encapsulation.java

2.CSDN: https: //blog.csdn.net/weixin_44630050 (Xi Jun Jun Moods do not know - Rui)

3. Park blog: https: //www.cnblogs.com/ruigege0000/

4. Welcomes the focus on micro-channel public number: Fourier transform public personal number, only for learning exchanges, backstage reply "gifts" to get big data learning materials

 

 

Guess you like

Origin www.cnblogs.com/ruigege0000/p/11639132.html