Java Anonymous inner class

Source: Internet
Author: User

Anonymous inner class: we can use an inner class to create an object with no name and use it to access members in the class. The main purpose is to simplify the program code and to complement the method that is not defined in the inner class.

public class app8_19{

public static void Main (String args[]) {

(//Define anonymous inner class start

New Caaa () {

void Set_num (int n) {

num = n;

System.out.println ("num=" +num);

}

}.set_num (5);

)//define Anonymous inner class end

}

Defining Inner Classes

Static Class caaa{

int num; Define variables only, do not define methods

}

}

Java 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.