Java Learning--the fourth day of basic knowledge--notes

Source: Internet
Author: User
Tags modifier modifiers

Today's content
Package
Permission modifiers
Inner class


Packages (Package)
The role of the package
Used to classify and manage Java files

Features of the package
(1) can be multi-layered, between each layer with. To separate
(2) Under the same package cannot have the same name class, under different packages can have the same name class
(3) Package declaration use the Package keyword, the packet declaration must be in the first line of the file valid code

Naming conventions for packages:
All lowercase, if multiple layers are used. To separate
is generally the company domain name backwards write, Www.itheima.com->com.itheima

Classes under different packages are accessed from each other
Classes under the same package can access each other
Access to classes under different packages requires a guide package, using the Import keyword

Shortcut keys for guide packages:
alt+/
Ctrl+shift+o

Permission modifiers (4)
Public > Protected > Default > Private

This class is a subclass of different packages, other classes of different packages
Public√√√√
Protected√√√
Default √√
Private√


Summary of modifiers
Permission modifiers
Public, protected, default, private
Other modifiers
Static, abstract, final


You can modify the following content:
Class (two more than member variables)
Public, default, abstract, final

Member variables (except abstract cannot be modified, other six kinds can be decorated)
Public, protected, default, private
Static, Final

Local variables (only two types)
Default, Final

Member methods (both can be decorated)
Public, protected, default, private
Static, abstract, final

Constructor method (only permission modifiers can be decorated)
Public, protected, default, private

Inner class
Components in a class
Member variable (constant)
Member methods (including getters methods and setters methods)
Construction method (non-parametric construction method, parameter construction method)
code block (static code block, construction code block)
Internal classes (interfaces, enumerations)

Classification:
member Inner class
Location: Outside of method in class
Local inner class
Location: In method
Anonymous inner class (master)
Location: In method


member Inner class
Characteristics:
Defined outside the method in the class, as well as the member variable and the position defined by the Member method
Member inner classes can use members of external classes directly, including private

Creating objects
Format:
The external class name. Internal class Name Object name = new External class name (). New internal class name ();
For example:
Outer.Inner i = new Outer (). New Inner ();

Modifier for member Inner class
Public, protected, default, private
Static, abstract, final

Private decoration
Can only be used in this class and cannot be used in other classes
static modifier
Calling methods
Non-static methods
The external class name. Internal class Name Object name = new External class name. Internal class name ();
The name of the object. Method Name ();
For example:
Outer2.inner2 i = new Outer2.inner2 ();
I.function ();//here The function () method is a non-static method
Static methods
The external class name. The internal class name. Method Name ();
For example:
Outer2.Inner2.function ();//here The function () method is a static method

Local inner class
Characteristics:
Defined in the method, the method in which it is located is not available
You must first define a local inner class, and then use the

Use:
You can only create an object of that local inner class in the same method as the local inner class, and then call the method in the local inner class

Anonymous inner class
Characteristics:
Defined in the method.
Can essentially be seen as a local inner class of every name
Creates an object of an anonymous inner class

To create an anonymous inner class object format
New interface () or parent class (parameter) {

};

The essence of an anonymous inner class object is to create a subclass object of that parent class, or an implementation class object for that interface

Application Scenarios
Pass as the actual parameter

Java Learning--the fourth day of basic knowledge--notes

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.