Day 13 Abstract Class

Objective Today, we're taking what we learned yesterday about Inheritance and extending it to Abstract Classes. Because this is a very specific Object-Oriented concept, submissions are limited to the few languages that use this construct. Check out the Tutorial tab for learning materials and an instructional video!

day13.1.png
day13.2.png

Here is my solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

abstract class Book {
String title;
String author;

Book(String title, String author) {
this.title = title;
this.author = author;
}

abstract void display();
}

// Declare your class here. Do not use the 'public' access modifier.
// Declare the price instance variable

/**
* Class Constructor
*
* @param title The book's title.
* @param author The book's author.
* @param price The book's price.
**/
// Write your constructor here

/**
* Method Name: display
*
* Print the title, author, and price in the specified format.
**/
// Write your method here

// End class

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();
}
}
2 min. read