class Person #继承该副类
def initialize(name,age)
@name=name
@age=age
puts "This is the Father Class #{@name},#{@age}"
end
def Call1
puts "The name is #{@name},and the age of him is #{@age}" #defination
end
def Function1
puts "Sleeping...Age:9"
end
def getPublic
puts "此处调用私有方法:"
self.Function1
end
private :Function1
end
father=Person.new("charles",23)
father.getPublic
出现问题如下:
This is the Father Class charles,23
/home/rcctp00013258/RubymineProjects/Project1/Succeed/father.rb:20:in `getPublic'此处调用私有方法:
: private method `Function1' called for #<Person:0x000000015c7668 @name="charles", @age=23> (NoMethodError)
from /home/rcctp00013258/RubymineProjects/Project1/Succeed/father.rb:27:in `<main>'
Process finished with exit code 1