标签:nbsp 默认 add end 访问 chap com hone zhang
(1)public 默认的访问权限,没有关键字
(2)protected 只能子类访问,同胞访问不了
(3)private 私有权限,只能当前类访问
(4)private[包名] 当前包访问
package chapter02 package p1{ package p2{ class UserP2{ var username="zhangshan" private var password="1234" //当前类可以调用 protected var email="123.com" //子类可以调用 private[p2] var address="XXXXXX" //p2可以调用 private [p3] var phone=186 //p3包可以调用 } } package p3{ import chapter02.p1.p2.UserP2 class EmpP3{ def test(): Unit ={ var user= new UserP2() user.username user.phone } } class StudentP3 extends UserP2{ def test(): Unit ={ var user=new UserP2 user.username user.email user.phone } } } }
标签:nbsp 默认 add end 访问 chap com hone zhang
原文地址:https://www.cnblogs.com/hapyygril/p/13405407.html