) define a class in the class (private internal class, static internal class)
(2) define a class in the method (Local internal class, anonymous internal
inheritance, with the following syntax:New Anonymous inner class class body};Based on an anonymous inner class that implements an interface, the syntax is as follows:New Anonymous inner class
no constructors, and it must inherit other classes or implement other interfaces . The benefit of using anonymous inner classes is to make your code more concise, but it can make your code less readable. It is generally used for event handling in GUI programming. Anonymous inner Classes cannot define their own static members, methods, and classes . The anonymous
classes require an inner class object to access members of an inner class, regardless of whether the inner class definition is in a member location or a local location, and the inner class obtains an external class object (the system provides an external
=NewOuter (); -Out.method (7); -Out.method (8); - } in -}4. Anonymous inner class1) The anonymous inner class is actually the shorthand format for the inner class.2) The premise of defining an anonymous inner class: An inner
In Java, an inner class is a class that is redefined within an outer class (that is, a class in a class). The class name does not need to be the same as the folder.Internal classes are
JAVA Inner class
One, what is the internal class?
The definition of a class is placed inside another class, and this class is called an inner class
What are the characteristics of th
Absdemo () {@Overridevoid Show () {System.out.println ("Inner:show");} Subclass-specific methods void method () {System.out.println ("method");}}. Show ();}}Call the parent class method at the back of the direct. Show () on the line, the subclass of the unique method how to call, do not think, can not be called, because the method subclass unique, subclass nameless son, there is no way to use the subclass of the instance to accept the object, if the
In Java, you can define member variables and methods within a class, and you can define classes within the class. This class is defined within the class as an inner class. The inner class
logic in its own, and therefore does not encourage Overriding the LoadClass method, and recommending overriding the Findclass method.In Java, any class needs to determine its uniqueness in the Java Virtual machine by the ClassLoader that loads it and the class itself, that is, to compare two classes for equality, only
public class Main {public
interface onclidk {
abstract void OnClick ();
}
void Test (Onclidk clk) {
clk.onclick ();
}
public static void Main (string[] args) {
//TODO auto-generated method stub
New Main (). Test (new Onclidk () {
PU Blic void OnClick () {
System.out.println ("Hello World");}}
Its essence is to implement an anonymous class
Java internal class types and usage parsingInner class inner classThe related classes are organized together, reducing the clutter in the namespaces.An inner class can be defined in another class and can be defined in a function or even as part of an expression. the inner c
, we know that what is actually needed is a subclass object.If the method is called only once, we can use the format of the anonymous inner class to simplify. (9) Anonymous inner class of face question (completion code)The code for the completion is:1:outer.method () can see that method () should be a static approach i
an anonymous class, the external local variable must be decorated as finalFinalintDamage =5; Hero h=NewHero () { Public voidattack () {System. out. printf ("new offensive means, resulting in%d damage.", damage); } }; } }Abstract Hero CodePackage charactor; Public Abstract classHero { Public Abstract voidattack (); Public Static voidMain (string[] args) {//using an external local variable
{//Spleen public void Storageblood () { //stored blood ... } } Private class Stomach {//Stomach public void Digest () {// digest ... } } Private class Kidney {//Kidney public void Dischargepoison () { //Detox ...}} }The issue of the derivation Because of the ability to access external private members, the problem was born, how did he access it?1: For the member inner
Java internal class refers to defining another class within an external class (or method), which can be divided into member internal class, local internal class, static internal 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
Course IntroductionObject-oriented is the most important feature of the Java language, this course focuses on object-oriented core knowledge, and uses a large number of code, data structure courses to deeply analyze Java object-oriented features.Course Objectives
Mastering Java Object-oriented development techniques
Suitable for people
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.