); } }}Anonymous inner class/ * Anonymous Inner class * is an inner class without a name, because this class only needs to be used once, so there is no need to name * 1. When creating an an
innerdemo03 {public static void main (string [] ARGs) {New outer (). method () ;}} abstract class person {abstract void Study ();} class Outer {private int num = 3; class student extends person // internal class {void Study () // override the study method of the parent class
You can place the definition of one class inside the definition of another class, which is the inner class.The definition of an inner class is simple, but its syntax is really complex and not very well understood. The following is a summary of the inner class.I. Classification of internal classesIn general, internal classes are divided into ordinary inner classes
Java initialization method: Class, container, java initialization container
Java initialization method: Class, containerInitialization class (non-final): In the DefaultActionMapper class
ActionListener interface, and obviously that class only needs to be instantiated once, so we can instantiate it with an anonymous inner class:New ActionListener () { publicvoid actionperformed (ActionEvent event) { ... }}; (5) Static inner classSometimes, we don't want an inner class to hold a reference to the Outer
JAVA basics: Find the class name-general Linux technology-Linux programming and kernel information from the. class file. The following is a detailed description. You can determine the name of a class in multiple ways:
Assume that all classes start with com, org, or net.
Search for a
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 classIn Java, one class is allowed to define another
Java-polymorphism, internal class, java-polymorphism,
1. Polymorphism:
1) meaning:
1.1) when a reference of the same type points to different objects, there are different implementations ------- behavior polymorphism: cut (), run (), teach ()...
1.2) the same object has different functions when it is modeled into different types ------- object polymorphism: Me, y
Why the anonymous intrinsic class parameter must be a final type:1) from the theory of the programming language: The local inner class (i.e., the inner class defined in the method ), because it is inside the method itself (can appear at the formal parameter definition or method body), thus accessing the method of the l
(i), the concept of internal classes1, the internal class is a compile-time concept, once compiled successfully, it is with the peripheral class belongs to two completely different classes (of course they are still connected).2. For a perimeter class named Outerclass and an inner class named Innerclass, after a success
One of the basic ideas of Java is that everything is an object, and a class is an object. But what is the object of the class? A class in Java is an instantiated object of Java.lang.Class, which is a class type.The main methods in
class because the inner class is free to use the member variables of the outer class (including private ones) without generating the outer class object. Iii. classification of inner classes and examples inner classes are divided into member inner classes, local inner classes, static inner classes, and
methods), that is, local classes.Local classes can only be accessed in the current statement block.Local classes can access local variables in the statement block (but must be modified using final)And Members in the external class.
More common anonymous classes
If a local class is used only once, it can be declared as an
limitations occur and only static members in the outer class can be accessed.Note: If a static member is defined in an inner class, the inner class must be static. The internal class is compiled with the file name: "External class name $ Internal
; } } public static void Main (string[] args) { Outerclass outerclass = new Outerclass (); Outerclass.innerclass innerclass = Outerclass.new innerclass (); Innerclass.getouterclass (). display ();} } -------------Output:outerclass ...Here we need to make it clear that the inner class is a compile-time concept, and once it's compiled, it's two completely different classes from the perimeter
Java internal classes and their instantiationIn Java, it is allowed to define another class within a class (or method, statement block), called an inner class (Inner Class), sometimes called a nested
variable members of this method can be accessed}}Innertwo innertwo = new Innertwo ();Innertwo.testprint ();}
public void use () {Inner innerobj = new Inner ()//At this time Inner have not seen.SYSTEM.OUT.PRINTLN (inner.x)//At this time Inner have not seen.}
public static void Main (string[] args) {Funouter outer = new Funouter ();Outer.test ();}}
From the above routines we can see that the inner class defined within the method is less visible, and
The Java Virtual machine class loading process is the process of loading the class file into memory and validating the data in the class file, parsing and initializing it, and finally forming a Java type that can be used directly by the virtual machine.During the load phase,
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.