We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 13: Abstract Classes
Day 13: Abstract Classes
Sort by
recency
|
594 Discussions
|
Please Login in order to post a comment
1) Inherit from Book You create a new class MyBook that uses Book as its base.
2) Constructor with 3 inputs:
title, author, and price
Use super() to send title and author to the parent (Book).
Then use self.price = price to save the price in this class.
3) Use self to store values
self.title, self.author, and self.price This means you’re saving the data inside the object so it can be used later.
4) Implement the display() method print()
Python 3
from abc import ABCMeta, abstractmethod class Book(object, metaclass=ABCMeta): def init(self,title,author): self.title=title self.author=author
@abstractmethod def display(): pass
Write MyBook class
class MyBook: def init(self, title, author, price): self.title = title self.author = author self.price = price def display(self):
title=input() author=input() price=int(input()) new_novel=MyBook(title,author,price) new_novel.display()
----------------MY full code ----- import java.io.; import java.util.;
abstract class Book { String title; String author;
}
class MyBook extends Book { int price;
}
public class Solution {
}
abstract class Book { String title; String author;
}
class MyBook extends Book { int price;
}