Java object-Oriented learning notes--6 (inner class, Timer)

Source: Internet
Author: User


1. Inner class

An inner class is a class defined inside a class, with a static inner class, a member inner class, a local inner class, and an anonymous inner class.

-1) Static inner class: Use static adornments, declared in the class body, static members of the external class can be accessed in the statically inner class, development is seldom used

650) this.width=650; "title=" Clipboard.png "src=" http://s3.51cto.com/wyfs02/M01/6D/7C/ Wkiom1vlk7rat6rwaai2cap7yb8231.jpg "alt=" Wkiom1vlk7rat6rwaai2cap7yb8231.jpg "/>

-2) member Inner class: declares in the class body, does not use static, has the member characteristics of the class, that is, must have an instance of the class to create an inner class instance, the inner class instance can access the member variables of the shared external class

650) this.width=650; "title=" Clipboard.png "src=" http://s3.51cto.com/wyfs02/M02/6D/77/ Wkiol1vllwpqovpoaah5ylbn21k437.jpg "width=" 657 "height=" 553 "alt=" Wkiol1vllwpqovpoaah5ylbn21k437.jpg "/>

-3) Local inner class: Declaring a class in a method is a local inner class, scoped like a local variable, and the class cannot be used without a method.

650) this.width=650; "title=" Clipboard.png "src=" http://s3.51cto.com/wyfs02/M00/6D/77/ Wkiol1vllxkqrw0oaahth2cthkc275.jpg "width=" 568 "height=" 553 "alt=" Wkiol1vllxkqrw0oaahth2cthkc275.jpg "/>

-4) Anonymous inner class: Very common, can be written anywhere, like the general statement, syntax is more like the creation of objects: TimerTask task = new TimerTask () {}; An anonymous class is an inheritance of the original class, and an instance is created, and {} is the class body that inherits later. The syntax of all classes can be used in a class body, an anonymous class cannot write a constructor, an anonymous class can inherit from an abstract class or an interface, and an implementation of an abstract method must be provided. If the anonymous inner class also uses a variable or object in the same method, it requires that the reference to the parameter be declared final.

650) this.width=650; "style=" width:650px;height:440px; "title=" Clipboard.png "src=" http://s3.51cto.com/wyfs02/ M01/6d/7c/wkiom1vllagrohwjaahcdpaxdr8558.jpg "width=" 687 "height=" 428 "alt=" wkiom1vllagrohwjaahcdpaxdr8558.jpg "/ >


2. Timers Timer Class

The timer is a timer class provided by the JDK that is used with the TimerTask Timer task class to implement timed tasks.

650) this.width=650; "title=" Clipboard.png "src=" http://s3.51cto.com/wyfs02/M00/6D/77/wKioL1VlLb3QH_ Jvaakegrgevz0352.jpg "alt=" Wkiol1vllb3qh_jvaakegrgevz0352.jpg "/>


This article is from "Forever Young" blog, please be sure to keep this source http://kingkongzhao.blog.51cto.com/6319491/1655532

Java object-Oriented learning notes--6 (inner class, Timer)

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.