继承的一个简单例子
2013-04-19 23:00
316 查看
package com; public class Cleaner { public int price; public Cleaner(int price) { this.price = price; } public void clean() { System.out.println("可以去污"); } public static void main(String[] args) { Soap s = new Soap(); System.out.println("肥皂的价格:" + s.price); s.clean(); s.shape(); WashingPowder p = new WashingPowder(); System.out.println("洗衣粉的价格:" + p.price); p.clean(); p.shape(); } } class Soap extends Cleaner { public Soap() { super(5); } public void shape() { System.out.println("呈块状"); } } class WashingPowder extends Cleaner { public WashingPowder() { super(10); } public void shape() { System.out.println("呈粉末状"); } }
相关文章推荐
- 一个简单继承的例子,面试失败的教训
- C#面向对象的一个简单例子,继承、接口、重写都用上了,还用到了工厂模式
- 一个简单的例子理解在JS原型继承中原型链是如何运作的
- 关于继承和多态的一个简单例子
- 一个类继承多个接口的简单例子
- 类继承一个简单的例子
- 一个动态编译的简单例子
- 使用Java开发一个非常简单的Web Service例子
- ucos-ii移植到ARM上的一个简单例子mini2440
- 一个简单的XML Schema的例子
- 一个简单的WebService例子
- 一个简单的C#多线程间同步的例子
- 一个最简单的Socket通信例子
- web.config文件自定义配置节的使用方法的一个简单例子
- 一个简单例子理解C语言指针
- 一个超简单的jQuery回调函数例子(分享)
- Delphi 一个简单的DELPHI自定义事件的例子
- 一个简单的双向链表的例子
- 一个简单的客户端调用xmlHttp的ajax例子
- Asp.net MVC4之 一个简单的小例子