HR30 Day 13: Abstract Classes

Jmnote (토론 | 기여)님의 2018년 8월 10일 (금) 02:12 판 (→‎PHP)

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 }}