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

6번째 줄: 6번째 줄:
{{HR30 10-19}}
{{HR30 10-19}}
|}
|}
==Java==
{{참고|HR30 Day 13: Abstract Classes/Java}}
<source lang='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);
    }
}
</source>


==PHP==
==PHP==

2018년 8월 10일 (금) 02:12 판

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";
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}