문서 편집 권한이 없습니다. 다음 이유를 확인해주세요: 요청한 명령은 다음 권한을 가진 사용자에게 제한됩니다: 사용자. 문서의 원본을 보거나 복사할 수 있습니다. ==개요== ;<nowiki>Day 4: Class vs. Instance</nowiki> * https://www.hackerrank.com/challenges/30-class-vs-instance/problem {{HR30 헤더}} {{HR30 0-9}} |} ==Java== {{참고|HR30 Day 4: Class vs. Instance/Java}} <syntaxhighlight lang='java'> public class Person { private int age; public Person(int initialAge) { // Add some more code to run some checks on initialAge if( initialAge < 0 ) { System.out.println("Age is not valid, setting age to 0."); initialAge = 0; } this.age = initialAge; } public void amIOld() { // Write code determining if this person's age is old and print the correct statement: if( this.age < 13 ) { System.out.println("You are young."); return; } if( this.age < 18 ) { System.out.println("You are a teenager."); return; } System.out.println("You are old."); } public void yearPasses() { // Increment this person's age. this.age++; } </syntaxhighlight> ==PHP== <syntaxhighlight lang='php'> <?php class Person{ private $age; public function __construct($initialAge){ if( $initialAge < 0 ) { echo "Age is not valid, setting age to 0.\n"; $initialAge = 0; } $this->age = $initialAge; } public function amIOld(){ if( $this->age < 13 ) { echo "You are young.\n"; return; } if( 13 <= $this->age && $this->age < 18 ) { echo "You are a teenager.\n"; return; } echo "You are old.\n"; } public function yearPasses(){ $this->age++; } } </syntaxhighlight> ==Python== <syntaxhighlight lang='python'> class Person: def __init__(self,initialAge): if initialAge < 0: print("Age is not valid, setting age to 0.") initialAge = 0 self.age = initialAge def amIOld(self): if self.age < 13: print("You are young.") return if 13 <= self.age and self.age < 18: print("You are a teenager.") return print("You are old.") def yearPasses(self): self.age += 1 </syntaxhighlight> 이 문서에서 사용한 틀: 틀:Ed (원본 보기) 틀:HR30 0-9 (원본 보기) 틀:HR30 헤더 (원본 보기) 틀:언어아이콘 (원본 보기) 틀:언어이미지 (원본 보기) 틀:참고 (원본 보기) HR30 Day 4: Class vs. Instance 문서로 돌아갑니다.