LoginSignup
2
1

クラスの作成とクラスの継承

Posted at

クラスの作成とクラスの継承を使ってプログラムを作りました。

class User
  attr_accessor :name
  @@count = 0
  VERSION = 1.1
  def initialize(name)
    @@count += 1
    @name = name
  end

  def sayHi
    # puts "私は#{@name}です"
    puts "私は#{self.name}です"
    # puts "私は#{name}です"
  end

  def self.info
    puts "User Class #{@@count} Instance Count"
    puts "#{VERSION}"
  end
end

class AdminUser < User
  def sayAdminUser
    puts "Hi! AdminUser #{name}"
  end
end

mai1 = User.new("白石麻衣")
mai1.sayHi
mai2 = AdminUser.new("白石麻衣")
mai2.sayAdminUser
AdminUser.info

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1