java-modifier-Package-inner class

Source: Internet
Author: User
Tags modifiers


1. Access permission modifiers

The order from large to small is: public--protected--default--private

private--can only be used in the same class;

default--does not need to write, default does not add. Can be used by classes in the same package

protected--can be used by subclasses of different packages

public--can be used by other classes of different packages


2. modifier objects for various modifiers (which can be modified: class/Interface/Method/property)

1) access modifier: Public/default---can be modified class/interface

Private protected cannot be decorated class. Default can be modified class, but not written out;

2) Static modifier: Static--modifier attribute/method/can only decorate inner class/code block;

Modifiers that cannot coexist with static: abstract (with three unknown origin)

3) final--the parameters in the modified class/attribute/method/method (can be accessed by local internal classes after decoration);

4) abstract--modified class/method;


3. About modifiers by default:

The interface defaults to public;

The variables in the interface default to public static final (that is, constant, all caps are required for naming);

The method in the interface defaults to public abstract;

If the permission modifier for a method in a class is not written, default is defaulted: for example:

Interface ia{

void Show ();//After compilation: Public abstract void Show ();

}

Class A implements ia{

void Show () {//Rewrite error: The default access modifier used here is smaller than the access modifier of the parent class, which is not allowed.

System.out.println ("Hello");

}

}

Main () {

New A (). Show ();

}




==========================================================================================


3. Package

Java package, in fact, is the folder in the computer, the package is stored in the. class file, when the class file a lot of time, the use of multiple packages for storage, known as sub-package management.

1). The class used is in a package with the current class, no need to guide the package;

2). The class used in the Java.lang no need to guide the package;

3). Other circumstances must guide the package;

4). Java Common System Package:

java.lang--Basic Package, automatic import, string, etc. are in this package;

java.lang.reflect--reflection mechanism of the packet, Java.lang of the child package;

java.util--Toolkit, Common class Library/date operation, etc.

Processing class library for java.text--text

java.sql--Database operation package, providing classes and interfaces for various types of database operations

java.net--Network Programming related

java.io--Input/output processing

java.awt--multiple classes that make up the abstract window toolset, which are used to build and manage the GUI

javax.swing--creating a graphical user interface


5). Summary of packages used so far:

Java.lang--string System stringbuffer StringBuilder wrapper class Thread

Java.util--scanner Random ArrayList Arrays Date objects

Java.io--bufferdreader BufferedWriter FileReader FileWriter

Java.math--bigdecimal BigInteger

=============================================================================================================== =========


4. Inner class--member inner class-Local inner class-Anonymous inner class

1) Inner classes, also known as nested classes (official parlance), are classes that are written in classes. The inner class of the member (written in the member variable position) and the local inner class (written in the method, seldom used). The anonymous inner class is one of the local inner classes.

2) All members in an external class can be accessed directly in the inner class

3) about access to local variables/internal class member variables/external class member variables

public class Outer {

int a = 100;

Class inner{

int a = 200;

public void PrintA () {

int a = 300;

SYSTEM.OUT.PRINTLN ("local variable a=" +a);//300

SYSTEM.OUT.PRINTLN ("Variable a= of the inner class" +THIS.A);//200

SYSTEM.OUT.PRINTLN ("Variable a= of the outer class" +OUTER.THIS.A);//100

}

}

}

4) An anonymous inner class is a shortcut to create a subclass object of a type, so the anonymous inner class is premised on having a parent class or interface.


java-modifier-Package-inner class

Related Article

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.