class Test
def method1
#默认为公有方法
…
end
protected#保护方法
def method2
…
end
private#私有方法
def method3
end
public
def test_protected(arg) #arg是Test类的对象
arg.method2 #正确,可以访问同类其他对象的保护方法
end
def test_private(arg) #arg是Test类的对象
arg.method3######错误,不能访问同类其他对象的私有方法
end
end
为什么说arg.method3是被其他对象调用,是被哪个对象调用了?新手,请高手帮下忙。
arg本身就是Test的一个类,我不明白的是如果private不能被本类对象调用,那他的作用是什么?