集册 Java实例教程 创建抽象类并将其扩展以创建另一个类

创建抽象类并将其扩展以创建另一个类

欢马劈雪     最近更新时间:2020-01-02 10:19:05

485
创建抽象类并将其扩展以创建另一个类



import java.util.*;/*NowJava.com - 时代Java 提 供*/


public class Main {


    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);

        String title = sc.nextLine();

        String author = sc.nextLine();

        int price = sc.nextInt();

        Book new_novel = new MyBook(title, author, price);

        new_novel.display();

    }

}


abstract class Book {/** 来 自 时 代 J a v a**/


    String title;

    String author;


    Book(String t, String a) {


        title = t;

        author = a;

    }


    abstract void display();

}


class MyBook extends Book {

    private int price;


    MyBook(String title, String author, int price) {


        super(title, author);

        this.price = price;

    }


    @Override

    void display() {

        System.out.println(
展开阅读全文