Java Object-oriented

Source: Internet
Author: User

Overview and role of the package keyword
A: Why should I have a bag
Classify byte code (. Class)
The package is actually a folder

Package Definition and Precautions
A: Define the format of the package
Package name;
Multi-stage ladle. Separate
B: Considerations for defining packages
The A:package statement must be the first executable code of the program
The B:package statement can have only one in a Java file

Access between classes under different packages
A: Case Demo
Access between classes under different packages
B: Guide Package format
Import package name;
Attention:
This way the import is to the name of the class.
Although it can be written last *, but not recommended.
C:package,import,class there is no sequential relationship

Common modifiers used by the class and its composition
A: modifier:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final
Abstraction modifier: Abstract
B: Class:
Permission modifiers: default modifier, public
Status modifier: Final
Abstraction modifier: Abstract

The most used is: public

C: Member Variable:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final

The most used is: private

D: Construction Method:
Permission modifiers: Private, default, Protected,public
  
The most used is: public

E: Member Method:
Permission modifiers: Private, default, Protected,public
Status modifier: static,final
Abstraction modifier: Abstract

The most used is: public


Internal class overview and accessibility features
A: Internal class overview
B: Internal class Access features
A: The inner class can access the members of the external class directly, including the private.
B: The external class must create an object to access the members of the inner class.
The external class name. Internal class Name Object name = External Class object. Inner class object;

Static member Inner class
Static
B: The member inner class is accessed by statically modifying the following methods:
The external class name. Internal class Name Object name = External class name. Inner class object;


Problems with local internal classes accessing local variables
A: Case Demo
Local internal class access local variables must be final decorated
Local inner class in accessing the local variables in his method must be final decorated, why?
Because when this method is called, if the local variable is not final decorated, his life cycle and method life cycle is the same, when the method of the stack, the local variable will disappear, then if the local inner class object has not disappeared immediately want to use this local variable, there is no,

If the final decoration will enter the constant pool when the class loads, even if the method is stacked, the constant pool constant is still there, you can continue to use

But jdk1.8 canceled this thing, so I think it's a bug.

The format and understanding of anonymous inner classes
A: Anonymous Inner class
is the simplified notation of the inner class.
B: Premise: There is a class or interface
The class here can be either a concrete class or an abstract class.
C: Format:

New class name or interface name () {
Override method;
}
D: What is the essence?
is an anonymous object that inherits the class or implements the interface's subclass.

Java Object-oriented

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.