Skip to content

Instantly share code, notes, and snippets.

@chrisjlee
Last active August 29, 2015 13:56
Show Gist options
  • Save chrisjlee/8793715 to your computer and use it in GitHub Desktop.
Save chrisjlee/8793715 to your computer and use it in GitHub Desktop.
Declaring a Person object in all various computer programming languages.
public class Person {
private String name;
private String age;
private String gender;
Person(String Name, String Age, String Gender) {
this.age = Age;
this.gender = Gender;
this.name = Name;
}
public static void main(String[] args) {
Person tim = new Person("Tim", "22", "Male");
System.out.println(tim.describe());
System.out.println(tim.greet());
}
public String greet() {
return "Hello " + this.name + "!";
}
public String describe() {
return this.name + " is a " + this.gender + " and " + this.age + " years old.";
}
}
var Person = function (name, age, gender) {
this.name = name;
this.age = age;
this.gender = gender;
};
Person.prototype.greet = function () {
return "Hello " + this.name + "!";
};
Person.prototype.describe = function () {
return this.name + ' is a ' + this.age + ' year old ' + this.gender + '.';
};
var tim = new Person('Tim', '22', 'Male');
tim.describe();
tim.greet();
<?php
public class Person {
protected $name;
protected $age;
public function greet () {
return "Hello " . $this->name "!";
}
public function describe() {
return $this->name . ' is a ' . $this->age + ' year old ' + $this->gender;
}
public __construct($name, $age, $gender) {
$this->name = $name;
$this->age = $age;
$this->gender = $gender;
}
}
$tim = new Person('Tim', '22', 'Male');
$tim->describe();
$tim->greet();
class Person(object):
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
def greet()
return "Hello " + self.name + "!"
def describe()
return self.name + " is a " + self.age + " year old " + self.gender + "."
tim = Person('Tim', '22', 'Male')
print tim.describe()
print tim.greet()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment