"HR30 Day 13: Abstract Classes"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
9번째 줄: 9번째 줄:
==Java==
==Java==
{{참고|HR30 Day 13: Abstract Classes/Java}}
{{참고|HR30 Day 13: Abstract Classes/Java}}
<source lang='Java'>
<syntaxhighlight lang='Java'>
class MyBook extends Book {
class MyBook extends Book {
     int price;
     int price;
22번째 줄: 22번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{참고|HR30 Day 13: Abstract Classes/PHP}}
{{참고|HR30 Day 13: Abstract Classes/PHP}}
<source lang='php'>
<syntaxhighlight lang='php'>
class MyBook extends Book
class MyBook extends Book
{
{
40번째 줄: 40번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==Python==
==Python==
{{참고|HR30 Day 13: Abstract Classes/Python}}
{{참고|HR30 Day 13: Abstract Classes/Python}}
<source lang='python'>
<syntaxhighlight lang='python'>
#Write MyBook class
#Write MyBook class
class MyBook(Book):
class MyBook(Book):
54번째 줄: 54번째 줄:
         print( 'Author:', self.author )
         print( 'Author:', self.author )
         print( 'Price:', self.price )
         print( 'Price:', self.price )
</source>
</syntaxhighlight>

2021년 7월 31일 (토) 10:34 기준 최신판

1 개요[ | ]

Day 13: Abstract Classes
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 Java[ | ]

class MyBook extends Book {
    int price;
    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    public void display() {
        System.out.printf("Title: %s\n", this.title);
        System.out.printf("Author: %s\n", this.author);
        System.out.printf("Price: %d\n", this.price);
    }
}

3 PHP[ | ]

class MyBook extends Book
{
    protected $price;
    function __construct($title, $author, $price) {
        parent::__construct(trim($title), trim($author));
        $this->price = $price;
    }
    function display() {
        echo 'Title: ' . $this->title . "\n";
        echo 'Author: ' . $this->author . "\n";
        echo 'Price: ' . $this->price . "\n";
    }
}

4 Python[ | ]

#Write MyBook class
class MyBook(Book):
    def __init__(self,title,author,price):
        super().__init__(title,author)
        self.price = price
    def display(self):
        print( 'Title:',self.title )
        print( 'Author:', self.author )
        print( 'Price:', self.price )
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}