java子類的對(duì)象為什么不能訪問父類的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í)例化的對(duì)象取不到protected了?
萌新!java子類的對(duì)象為什么不能訪問父類的protected變量?
牧羊人nacy
2019-08-17 20:44:46