White Journey 11-1

A simple demonstration of annotations

format:

@单词

Location: top members
such as:

@xxx
String name;

@xxx
public void f(){
}

JUnit4 common notes:
1, the Before @: @Test priority to the implementation of, and each will be executed before @Test
2, @ Test: executive function
3, @ After: executed after @Test, and each will be after @Test carried out

II. Inner classes

Concepts: define a class code block

2.1 members of the inner class

The classes are defined in other members of the class position

2.1.1 format

public class Outer{
    class Inner{
    }
}

2.1.2 members of the inner class-related access methods

1, external access to internal class categories:

在外部类中创建内部类对象

2, internal access to external class categories:

直接访问(包括外部类中私有内容)

3, other types of access to the internal classes:

外部类.内部类 对象名 = new 外部类().new 内部类();

2.1.3 When to use inner classes

In describing a class of things, if the interior of such things can further comprise other things, as described, for example, an automobile engine, visceral body, where the engine type vehicles can be used as an internal class can be visceral the human body as an internal class class.

2.2 partial inner class

The class definition of the local position in the other class

2.2.1 format

public void 方法名(){
    class 内部类{
    }
}

Access mode: the method comprising the outer class within the class, the class object to create an internal, access

2.3 static inner classes

The internal members of the class definition in position, and static modification

2.3.1 format

public class Outer{
    static class Inner{
    }
}

2.3.2 static inner classes related access methods

1, the outer class access static inner classes:

在外部类中创建内部类对象

2, static inner classes to access external categories:

在内部类中创建外部类对象

3, other types of access static inner classes:

外部类.内部类 对象名 = new 外部类.内部类();

2.4 anonymous inner classes

Subclass objects created using anonymous, appeared in the local position

2.4.1 format

new 父类名/接口名(){
    // 重写方法
};

2.5.1 Role

Facilitate the creation of an abstract classes (interfaces) subclass (the implementation class) objects

III. Code block

By the "{}" enclosed section of code into

3.1 Normal (partial) block

Position is defined in the method or statement
it "{}" scoped code
method, the class is "{}" is defined boundary
format:

public void 方法(){
    {语句}
}

Configuration code block 3.2

Members define a position of the code block
format:

public class 类{
    {语句}
}

3.2.1 Features

  • Every object is to create a structure will be executed code blocks
  • Priority to the implementation of the constructor that initializes all objects to perform actions need to be performed

3.3 static code block

Members define a position, using a modified static block
format:

public class 类 {
    static{
        语句
    }
}

3.3.1 Features

  • The highest priority to the implementation of
  • Only once

3.3.2 Role

For the assignment of static variables

Guess you like

Origin www.cnblogs.com/demonycw/p/11329340.html