class Student2
attr_accessor :name
attr_accessor :no
attr_accessor :gender
def initialize(name,no,gender)
@name = name
@no = no
@gender = gender
end
# 这个方法是实例方法
def say_hello
puts @name
end
# self表示本身,这个方法是类方法
def self.nick_name
return "学生类"
end
end
#大学生类继承学生类:<
require Student
class UniversityStudent < Student
# 重写父类方法
def say_hello
puts "大学生#{@name}"
end
def say_english
p "my english is very good"
end
end
网友评论