constructor method. can be accessed directly with the interface name.Defined:Interface Inter {public static final int COUNT = 100;}Access:Inter.countthird, anonymous objectsAn anonymous object is a statement that creates an object, but does not assign an object address value to a variable.Create a Normal object
Person p = new person ();
Create an anonymou
of an anonymous inner class implementation of the 4:thread class?
public class Demo {public static void main(String[] args) {Thread t = new Thread() {public void run() {for (int i = 1; i 5; i++) {System.out.print(i + " ");}}};t.start();}}
Operation Result: 1 2 3) 4 5An
class Demo {public static void main (string[] args) {Person p = new person () {public void Eat () {System.out.println ("eat something");}};P.eat (); }}Operation Result: Eat somethingAs you can see, we directly implement the methods in the abstract class person in curly braces.This allows you to omit the writing of a classAlso, anonymous inner classes can be used
Anonymous inner class1. Definition:Implement an interface, or inherit a parent class, and return a good instance of new.2. Syntax:The implementation body of the new class name or interface name class3. What is the use of anonymous internal classes:Class is used immediately after it is created and is used only once4. No
Learning Android today, one way to implement the OnClick event for a button control is to use an anonymous class, where anonymous classes in Java are summarized.Anonymous inner class--an inner class without a name, because it has
many ways, it will be very troublesome. So choose to use parameters to receive this object, and then use the object to invoke the method on it. Inter i = new Inter () {//Interface implementation subclass object to interface, polymorphic public void Show () {System.out.println ("show");} public void Show2 () {System.out.println ("Show2");}};/ /note here the semicolon i.show (); I.show2 ();}} Class InnerClassDemo6 {public static void main (string[] arg
This time looking at Android, see the Java inside the anonymous inner class, in the impression. NET does not support anonymous inner classes.
Anonymous classes are classes that cannot have names, so there is no way to reference them. They must be declared as part of the new
."); } }); } Public Static voidShow (jumping jm) {jm.jump (); } Public InterfaceJumping {Final Public Static intnum = 10; Public Abstract voidJump ();} Public S
Anonymous inner class:
1, anonymous inner class is actually the abbreviated form of the internal class.
2, the premise of defining anonymous internal classes:
The inner class must in
class.The static code block executes only once, regardless of how many objects are created.Can be used to assign a value to a static variable for initialization of a class.1 Packagecom.oracle.demo04;2 3 Public classStatic {4 PrivateString name;5 Private intAge ;6 /*constructs a block of code to create an object to execute once*/7 //Building Code Blocks8 {9System.out.println ("This is the construction code block");Ten } One
Anonymous inner classis the simplified notation of local inner classes. premises: has a class or interface. new class name or interface name () { overriding method; } What is the nature of the anonymous inner class? A: An
1. The anonymous inner class is actually the shorthand form of the inner class.2. The premise of defining an anonymous inner class: The inner class must inherit a class, or implement an
2016-06-29Review:public class outer{Class inner{}}The member inner class.1 Anonymous Inner class Packagecom.java1995; Public classTestinner { Public Static voidMain (string[] args) {/*** Anonymous internal
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.