Skip to content
irxground edited this page Sep 9, 2013 · 1 revision

クラス定義

静的型付け言語

Java

public class User {
  private String name;

  public String getName() { return name; }
  public void setName(String name) { this.name = name; }

  public User(String name) {
    this.name = name;
  }
}

C#

public class User {
  public string Name { get; set; }

  public User (String name) {
    Name = name;
  }
}

Scala

class User(name: String);

動的型付け言語

Ruby

class User
  attr_accessor :name

  def initialize(name)
    @name = name
  end
end
User = Struct.new(:name)

PHP

<?php

class User {
  public $name;

  public __construct($name) {
    $this->name = $name;
  }
}

_sidebar

Clone this wiki locally