Last active
August 29, 2015 13:56
-
-
Save chrisjlee/8793715 to your computer and use it in GitHub Desktop.
Declaring a Person object in all various computer programming languages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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