The final keyword + package + mechanism to limit access modifier

1, finla is a keyword, marking the final, immutable
final class can not inherit the modified
final modification methods can not be covered by
final modifications after variable assignment once, can no longer assign
final modification of instance variables? ? ?
final modification of reference? ? ?
2, after the use of instance variables final modification, must be assigned default values can not adopt a systematic
final int age;compilation error
Solution one

final int age=100;

Solution two

final int num;
public Final(){
this.num=200;
}

3、

final User =new User(30);
User.id=50;报错

final modification of reference points to an object, can no longer point to other objects, name the pointed object can not be garbage Exhibition device

4, constant defines the syntax:
public static Final type constant name = value;
provisions: Constant university, underscore between each word
public static final string GUO_JI = 'China';

Pack mechanisms:
1, also known as bag package, java package referenced in this grammar mechanism is mainly to facilitate the management of the program
2, how the definition of package?
- java source code written in the first row on the package statement
-package can only write a statement
- grammatical structure
package package name
3, naming:
the company reverse domain name + + project module name + function name
4, a package corresponds to a directory
5 using import import the package

Access restrictions:
1, modifiers
public disclosure
protect the same package, a subclass of
the default packet with the
private private, this class

Published 40 original articles · won praise 0 · Views 397

Guess you like

Origin blog.csdn.net/weixin_43446514/article/details/104616161