Remember that in a written test question in an interview, some interviewers will ask for the scope of the specific access limited symbols like Pullic. In fact, I usually did not go to the system to consider the scope of the access limited character, especially in the inside of the bag, OK, the written test is not good.
This is the basic knowledge of Java, and it is also valued by the company. There is no way. My head can't remember things. Then I can only write down these things to make it easier for myself to know the new.
The code is as follows:
package com.jaovo;/***_1_Profitage of member variable access to verification*Public Private Protected Default Access accessable*other bags of other bags can access, non -accessable, non -access, non -access, non -access, no, other categories have inheritance relationships. Access non-access*------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------- *_2_ 成员方法访问权限的求证* public private protected default(默认的权限) *自己包You can access the accessable accessable accessable. Unacceptable accessible accessable*other bags have inheritance relationships. Chengyuan Extends C {// Public Class Chengyuan Extends D {Public Class Chengyuan Extends E {Public Static Void Main (String [] ARGS) {// A member variable permissions access/*1 b b b = new b (); // My own class System.out.println (B.I1); System.out.println (B.I2); System.out.println (B.I3); // i3 can access the private system.out in B .println (B.I4); *// *2 chengyuan ch = new cheenGyuan (); // package your own system System.out.println (ch.I1); system.out.println (ch.I2); .out.println (ch.I3); System.out.println (ch.I4); *// *3 d = new d (); // Other bags System.out.println (d. i1); System.out.println (d.I2); // I2 is not public in D; it cannot access System.out.println (D.I3) from the external program package; Visit the Private System.out.println (D.I4); // I4 can access ProteCted *// *4 chengyuan ch = new Chengyuan (); // System.out.println (ch.I1); System.out.println (ch.I2); System.out.println (ch.I3); // I3 can access system.out.println (ch.I4 ); *// *5 chengyuan ch = new cheengyuan (); // Other bags have inheritance relationships chengyuan extends d System.out.println (ch.I1); System.out.println (ch.I2) // I2 is not public in D; it cannot access System.out.println (CH.I3) from the external program package; // i3 can access the Private System.out.println (ch.I4 (ch.I4 ); */// ====================================== ========== // The access permissions of the two member methods/*1 chengyuan ch = new chengyuan (); // package your own class System.out.println (ch.m1 ()); System. out.println (ch.m2 ()); System.out.println (ch.m3 ()); system.out.println (ch.m4 ()); * / / *2 b b = new b (); // The other class System.out.println (b.m1 ()); System.out.println (b.m2 ()); System.out.println (B.M3 ()); // m3 ( ) You can access the private system.out.println (b.m4 ()); *// *3 e e e = new e (); // ()); System.out.println (e.m2 ()); // M2 is not public in E; cannot access System.out.println (e.m3 ()) from the external program package; // M3 can access the Private System.out.println (e.m4 ()); // M4 () can access the Protected *// *4 c C = New C (); // Pack it yourself. Other classes have inheritance relationships chengyuan extends c system.out.println (c.m1 ()); system.out.println (c.m2 ()); System.out.println (c.m3 ()); // m3 () can access system.out.println (c.m4 ()) in C; */// 5 chengyuan ch = new chengyuan (); system.out.println (ch.m1 ()); .println (ch.m2 ()); // Can't find the symbol System.out.println (ch.m3 ()); // Can't find the symbol System.out.println (ch.m4 ());}}}} Class B {// 1 member variable public int i1 = 100; int i2 = 200; Private int i3 = 300; Protect int i4 = 400; // 2 member method Public Int m1 () {Return 1;} int m2 () {Return 1;} Private int M3 () {Return 1;} Protected Int m4 () {Return 1;} Class C {// 1 member variables public int i1 = 100; = 300 ; ProteCted Int I4 = 400; // 2 Members Public Int M1 () {Return 1;} int m2 () {Return 1;} Private int m3 () {Roturn 1;} Protected m4 () {Return 1; }} // ======================================= ========== // d.class file and E.Class file in the CN package, in order to facilitate them here = 100; int i2 = 200; Private int i3 = 300; ProteCted int i4 = 400; // 2 member method public int m1 () {return 1;} int m2 () {regurn 1;} Private int m3 () {) { return 1;} protected int m4(){return 1;}}//-------package cn.jaovo;public class E{ //1 成员变量public int i1 = 100; int i2 = 200; private int i3 = 300; ProteCted int i4 = 400; // 2 member method Public int M1 () {Return 1;} int m2 () {Return 1;} Private Int m3 () {Return 1;} Protect into M4 ( Cure {return 1;}}
The above code is a detailed explanation of the member methods of members in Java and member variable access. I hope everyone likes it.