java子類的對象為什么不能訪問父類的protected變量?相關(guān)代碼packageChapter6.Chapter6A;//父類代碼publicclassChapter6exp{intage=5;protectedStringname="zzz";privatevoidf(){};publicStringcity="QD";}子類代碼,位于不同包內(nèi)packageChapter6;importChapter6.Chapter6A.Chapter6exp;classCextendsChapter6exp{C(){//this.city;//this.name;}}publicclassHuman{publicstaticvoidmain(Stringargs[]){Cc=newC();//c.city;只能取到city(public)}}在子類內(nèi)部可以取到protected和public變量是我預(yù)期的,但是為什么實(shí)例化的對象取不到protected了?
請各位大佬指點(diǎn)!java子類的對象為什么不能訪問父類的protected變量?謝謝哈~
繁華開滿天機(jī)
2019-08-30 01:08:31