Java Section 41st anonymous inner class

Source: Internet
Author: User

2016-06-29

Review:
public class outer{
Class inner{
}
}
The member inner class.

1 Anonymous Inner class

 Packagecom.java1995; Public classTestinner { Public Static voidMain (string[] args) {/*** Anonymous internal class Outeri () {..}; * New implementation class for an interface*/Outeri Outer=NewOuteri () {@Override Public voidShow () {//TODO auto-generated Method StubSystem.out.println ("This is the show method for anonymous inner classes");        }                    };        Outer.show (); /*** Anonymous internal class PA () {...}; * Subclass inherits the parent class and overrides the parent class's method*/Pa P=NewPa () { Public voideat () {System.out.println ("Subclasses are eating.");                }        };            P.eat (); }}//Defining InterfacesInterfaceouteri{ Public voidshow ();}//implementation Class A for the interfaceclassAImplementsouteri{@Override Public voidShow () {//TODO auto-generated Method Stub            }    }classpa{ Public voideat () {System.out.println ("The parent class is eating."); }}

Resources

[1] Java Easy Start Classic tutorial "full version"

Java Section 41st anonymous inner class

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.