集册 Java实例教程 扩展抽象类

扩展抽象类

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

554
扩展抽象类

     


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


abstract class Book

{

    String title;

    String author;

    Book(String t,String a){

        title=t;

        author=a;

    }

    abstract void display();
    /**
    时 代 J a v a - nowjava.com
    **/



}

class MyBook extends Book{

    String title;

    String author;

    int price;

    MyBook(String t,String a,int p){

        super(t,a);

        this.title=t;

        this.author=a;

        this.price=p;

    }

    void display(){

        System.out.println("Title: "+title);

        System.out.println("Author: "+author);

        System.out.println("Price: "+price);

    }

}

public class Main{

   

   public static void main(String []args)

   {

      Scanner sc=new Scanner(System.in);

      String title=sc.nextLine();

    
展开阅读全文