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

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
 
3번째 줄: 3번째 줄:
* [[HR30 Day 13: Abstract Classes]]
* [[HR30 Day 13: Abstract Classes]]


<source lang='java'>
<syntaxhighlight lang='java'>
import java.util.*;
import java.util.*;


17번째 줄: 17번째 줄:
     abstract void display();
     abstract void display();
}
}
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
class MyBook extends Book {
class MyBook extends Book {
     int price;
     int price;
44번째 줄: 44번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>
<source lang='java'>
<syntaxhighlight lang='java'>
public class Solution {
public class Solution {
    
    
59번째 줄: 59번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>

2021년 10월 12일 (화) 23:54 기준 최신판

개요[ | ]

import java.util.*;

abstract class Book {
    String title;
    String author;
    
    Book(String title, String author) {
        this.title = title;
        this.author = author;
    }
    
    abstract void display();
}
class MyBook extends Book {
    int price;
    /**   
    *   Class Constructor
    *   
    *   @param title The book's title.
    *   @param author The book's author.
    *   @param price The book's price.
    **/
    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    /**   
    *   Method Name: display
    *   
    *   Print the title, author, and price in the specified format.
    **/
    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);
    }
}
public class Solution {
   
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String title = scanner.nextLine();
        String author = scanner.nextLine();
        int price = scanner.nextInt();
        scanner.close();

        Book book = new MyBook(title, author, price);
        book.display();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}