-
Notifications
You must be signed in to change notification settings - Fork 183
/
14 - Day 13 - Abstract Classes.cs
51 lines (41 loc) · 1.06 KB
/
14 - Day 13 - Abstract Classes.cs
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
48
49
50
51
// ========================
// Information
// ========================
// Direct Link: https://www.hackerrank.com/challenges/30-abstract-classes/problem
// Difficulty: Easy
// Max Score: 30
// Language: C#
// ========================
// Solution
// ========================
using System;
using System.Collections.Generic;
using System.IO;
abstract class Book {
protected String title;
protected String author;
public Book(String t, String a) {
title = t;
author = a;
}
public abstract void display();
}
//Write MyBook class
class MyBook : Book {
private int price = 0;
public MyBook(String title, String author, int price) : base(title, author) {
this.price = price;
}
public override void display() {
Console.Write("Title: {0} \nAuthor: {1} \nPrice: {2}", title, author, price);
}
}
class Solution {
static void Main(String[] args) {
String title = Console.ReadLine();
String author = Console.ReadLine();
int price = Int32.Parse(Console.ReadLine());
Book new_novel = new MyBook(title, author, price);
new_novel.display();
}
}