Sort by

recency

|

593 Discussions

|

  • + 0 comments
    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(Book):
        def __init__(self, title, author, price):
            super().__init__(title,author)
            self.price = price
        def display(self):
            print('Title:',self.title)
            print('Author:',self.author)
            print('Price:',self.price)
    
    title=input()
    author=input()
    price=int(input())
    new_novel=MyBook(title,author,price)
    new_novel.display()
    
  • + 0 comments

    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):

        print(f"Title: {self.title}")
        print(f"Author: {self.author}")
        print(f"Price: {self.price}")
    

    title=input() author=input() price=int(input()) new_novel=MyBook(title,author,price) new_novel.display()

  • + 0 comments

    ----------------MY full code ----- import java.io.; 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;

    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    void display() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Price: " + 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 new_novel = new MyBook(title, author, price);
        new_novel.display();
    }
    

    }

  • + 0 comments

    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;

    MyBook(String title, String author, int price) {
        super(title, author);
        this.price = price;
    }
    
    void display() {
        System.out.println("Title: " + title);
        System.out.println("Author: " + author);
        System.out.println("Price: " + price);
    }
    

    }

  • + 1 comment

    Just MyBook class Python implementation code:

    # Write MyBook class
    class MyBook(Book):
        def __init__(self, title, author, price):
            self.title = title
            self.author = author
            self.price = price
            
        def display(self):
            print(f"Title: {self.title}")
            print(f"Author: {self.author}")
            print(f"Price: {self.price}")