Java internal class

Source: Internet
Author: User
/***** @ Classname: Demo * @ Description: static internal classes can contain static or non-static members, but non-static internal classes can only contain non-static members; * methods in the static internal class can only access static attributes in the external class, while methods in the non-static internal class can access static or non-static attributes in the external class; * attribute format of the internal class to access the external class: External class name. this. non-static attribute name external class name. this. static member name (only available in non-static internal classes) * external class name. static attribute name external class access static internal class format: internal class name. static member name external class access internal class format: New * external class name. internal Class Name (). internal class member name or new internal class name (). internal class member name * @ author wangzhu * @ date 2012-10-9 10:45:14 */public class demo {protected static int NUMA = 1; private int numb = 2; private Static Class A {int NUMA = 11; static int numaa = 22; static void Showa () {system. out. println (NUMA + "" + demo. NUMA + "" + numaa);} void show () {system. out. println (NUMA + "" + demo. NUMA + "" + NUMA + "" + numaa) ;}} private class B {int numb = 111; void showb () {system. out. println (NUMA + "" + numb + "" + demo. NUMA + "" + demo. this. NUMA + "" + demo. this. numb + "" + "" + numb) ;}} public void showdemo () {system. out. println (NUMA + "" + numb); system. out. println (demo. a. numaa + "" +. numaa);. showa (); demo. a. showa (); demo. A demoa = new demo. A (); demo. B demob = new demo. B (); A = new A (); B = new B (); system. out. println (demoa. NUMA + "" + demoa. numaa); demoa. show (); demoa. showa (); system. out. println (demob. numb); demob. showb (); system. out. println (. NUMA + "" +. numaa);. show ();. showa (); B. showb (); system. out. println (B. numb); A = new demo. A (); demoa = new A (); system. out. println (. NUMA + "" +. numaa);. show ();. showa (); system. out. println (demoa. NUMA + "" + demoa. numaa); demoa. show (); demoa. showa (); B = new demo. B (); demob = new B (); system. out. println (B. numb + "" + demob. numb); B. showb (); demob. showb ();} public static void main (string [] ARGs) {new demo (). showdemo ();} // 1 2 // 22 22 // 11 22 // 11 22 ///11 22 // 11 22 ///1 111 22 // 11 22 // 111 // 1 211 2 111 // 11 22 // 1 111 22 // 11 22 // 1 211 2 111 // 111 // 11 22 ///1 111 22 // 11 22 // 11 22 // 1 111 22 // 11 22 // 111 111 211 // 1 111 2 211 // 1 111 2}

 

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.