吃鸡游戏
packageTypeVarMembers;classC{publicvoidmCPublic(){}protectedvoidmCProtected(){}voidmCPackage(){}privatevoidmCPrivate(){}}interfaceI{voidmI();}classCTextendsCimplementsI{publicvoidmI(){}}classTest{voidtest(Tt){t.mI();//OKt.mCPublic();//OKt.mCProtected();//OKt.mCPackage();//OKt.mCPrivate();//Compile-timeerror}}ThetypevariableThasthesamemembersastheintersectiontypeC&I,whichinturnhasthesamemembersastheemptyclassCT,definedinthesamescopewithequivalentsupertypes.Themembersofaninterfacearealwayspublic,andthereforealwaysinherited`(unlessoverridden).HencemIisamemberofCTandofT.AmongthemembersofC,allbutmCPrivateareinheritedbyCT,andarethereforemembersofbothCTandT.IfChadbeendeclaredinadifferentpackagethanT,thenthecalltomCPackagewouldgiverisetoacompile-timeerror,asthatmemberwouldnotbeaccessibleatthepointwhereTisdeclared.来自TheJava®LanguageSpecification,JavaSE8Edition$4.4TypeVariablesP58~59