当前位置: 代码迷 >> 综合 >> Ruby面向对象 protected
  详细解决方案

Ruby面向对象 protected

热度:60   发布时间:2023-12-09 08:31:28.0



protected:

    和java不一样,不能被当前创建的类对象,有外部访问,但可以被传入的对象调用。

private :

   不能被传入的值调用

[ruby] view plain copy
  1. class AccessTest  
  2.   def test  
  3.     return "test private"  
  4.   end  
  5.   def test_other(other)  
  6.     return "dd"+other.test  
  7.   end  
  8. end  
  9. class AccessTest  
  10.   private :test  
  11. end  
  12. p1=AccessTest.new  
  13. cc=AccessTest.new  
  14. puts p1.test_other(cc) 
  相关解决方案