Final
- The final decorated class, which indicates that the class cannot be inherited
- The final modification method, which indicates that this method cannot be overridden
- Final modifier constant (constant capitalization), indicating that constants cannot be modified
- Static final-modified constants, representing global constants
Abstract class
- Class that uses the abstract modifier, which is a class of abstraction
- Using the abstract modified method, as an abstraction, this method only life is not implemented
- Classes that contain abstract methods must be abstract classes
- Abstract class cannot be instantiated, subclass of abstract class must override abstract method of parent class
- Cannot use the abstract modifier property, private method, constructor, static method, final method
/*我为抽象类*/abstract calss A { abstractvoid m();}
Interface (interface)
- An interface is a special abstract class with no attributes, only methods
- The interface is implemented by the class, and the implementing class must override all the methods in the interface
- Interface is a way to implement multiple inheritance in Java
- Interfaces are public-decorated, and methods are public
/*声明一个接口*/publicinterface Runner { publicvoidrun();}/*实现接口*/publicclass implements Runner { publicvoidrun() { System.out.printf("我会跑!"); }}
Inner class
In Java, one class is allowed to define another class, which becomes an outer class, which is called an inner class
- Inner classes can be declared as final
- Inner classes can be decorated as private or protected
- The inner class can be static, and the non-static member variable of the outer class cannot be used at this time
Public classTest { Public Static void Main(string[] args) {A A =NewA (); A.B B = A.NewB (); B.M (3); }}class A {Private ints =1; Public classBPrivate ints =2; Public void m(ints) {System. out. println (s);//3 Local VariablesSystem. out. println ( This. s);//2 objects for inner classesSystem. out. println (A. This. s);//1 objects of the outer class} }}
Anonymous inner class
General Swing is used more
Here is a use of the inner class
button.addListener( new OnClickListener() { //实现方法 });
"Java Summary" final keyword, abstract class, interface, inner class