Java语言程序设计教程(第二版)翁 凯 肖少拥 王行言-第6章--继承与多态

class Fiction implements Book{ double price; // 价格 int pages; // 页数

public Fiction(int pages, double price) { this.pages = pages; this.price = price; }

//实现接口方法Info() public void Info() {

System.out.println(\is a fiction, which has \+ pages + \pages,\costs \ } }

//杂志类

class Magazine implements Book { double price; // 价格 int pages; // 页数

String publish_time; // 出版时间 //构造方法

public Magazine(int pages, double price, String publish_time) { this.pages = pages; this.price = price;

this.publish_time = publish_time; }

//实现接口方法Info() public void Info() {

System.out.println(\pages,\costs \+ price + \yuan, and publish once every \+ publish_time + \ } }

//期刊类

class Journal implements Book{ double price; // 价格 int pages; // 页数

String publish_time; // 出版时间

public Journal(int pages, double price, String publish_time) { this.pages = pages; this.price = price;

this.publish_time = publish_time; }

//实现接口方法Info()

public void Info() {

System.out.println(\is a journal, which has \+ pages + \pages,\costs \+ price + \yuan, and publish once every \+ publish_time + \ } }

//课本类

class Textbook implements Book{

String applicable_object; // 适用对象 double price; // 价格 int pages; // 页数

public Textbook(int pages, double price, String applicable_object) { this.pages = pages; this.price = price;

this.applicable_object = applicable_object; }

//实现接口方法Info() public void Info() {

System.out.println(\pages,\applicable_object +\ } }

public class Test {

public static void main(String[] args) { Fiction f = new Fiction(199, 12); f.Info();

Magazine m

>>闂傚倸鍊峰ù鍥敋瑜忛幑銏ゅ箳濡も偓绾惧鏌i幇顖f⒖婵炲樊浜滈崘鈧銈嗗姧缂嶅棗岣块悢鍏尖拺缁绢厼鎳忚ぐ褏绱掗悩鍐茬仼缂侇喖鐗撳畷鎺楁倷鐎电ǹ甯惧┑鐘垫暩婵鎹㈠Ο渚€舵い鏇楀亾闁哄矉绲鹃幆鏃堫敍濞戞﹩浼�<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4