java abstract抽象类学习
2012-10-23 11:22
309 查看
java抽象类
java abstract class
有时候,我们需要用到抽象类。比如我们想买水果,但是不确定买的是苹果还是香蕉
Sometimes, we want to abstract a class.For example, We want buy some fruits,but we are not sure we buy apple or pear.
我们抽象出一个类叫水果
Now we can abstract a class named Fruit
水果就作为了一个抽象类和一个父亲类
Fruit is a abstract class and it is a father class.
苹果和梨就作为子类
Apples and pears fruit is child class
注意:我们不能获得一个抽象类的对象 new Fruit() 会发生错误。
note: can not get a new abstract class new Fruit() is wrong
child class
首发于http://java-er.com - http://java-er.com/blog/java-abstract/
java abstract class
有时候,我们需要用到抽象类。比如我们想买水果,但是不确定买的是苹果还是香蕉
Sometimes, we want to abstract a class.For example, We want buy some fruits,but we are not sure we buy apple or pear.
我们抽象出一个类叫水果
Now we can abstract a class named Fruit
水果就作为了一个抽象类和一个父亲类
Fruit is a abstract class and it is a father class.
苹果和梨就作为子类
Apples and pears fruit is child class
注意:我们不能获得一个抽象类的对象 new Fruit() 会发生错误。
note: can not get a new abstract class new Fruit() is wrong
abstract father class public abstract class Fruit { public String getColor(String color){ return color; } public String getWeight(String weight){ return weight; } }
child class
public class Apple extends Fruit { public String getColor(String color){ System.out.println(‘‘color is ‘‘ + color); return color; } public String getWeight(String weight){ System.out.println(‘‘weight is ‘‘ + weight); return weight; } public static void main(String[] args){ Fruit f = new Apple(); //Fruit f = new Fruit(); can not get a new abstract class new Fruit() is wrong f.getColor(‘‘red‘‘); } }
首发于http://java-er.com - http://java-er.com/blog/java-abstract/
相关文章推荐
- Java学习之面向对象(1.Object类,(1)toString方法,(2)equals方法,2.对象转型(casting),3.动态绑定与多态,4.抽象类(abstract),5.Final关键字)
- 黑马程序员—java基础学习--抽象类(abstract)、接口(interface)、多态
- java学习1、abstract 抽象函数 抽象类
- java学习笔记-抽象类abstract与接口interface
- Java开发手册 学习1:抽象类命名使用 Abstract 或 Base 开头
- JAVA学习第十三课(继承下:抽象类abstract)
- Java 学习笔记 (3) -抽象类 abstract 接口 interface 内部类 inner class 继承 extends 实现 implements 包 package
- java学习日志(4)——java中抽象类与接口的学习
- Java学习笔记9(面向对象二:this、继承、抽象类)
- Java学习(九) 抽象类与接口
- java学习过程中对抽象类的理解
- java接口:interface 的和抽象类:abstract
- JAVA之旅(七)——final关键字 , 抽象类abstract,模板方法模式,接口interface,implements,特点,扩展
- 【Java学习笔记】接口 抽象类 抽象方法
- 【幻化万千戏红尘】qianfengDay09-java基础学习:接口,抽象类,抽象方法,多态,instanceof
- JAVA学习--Abstract使用字段限制
- 共同学习Java源代码--数据结构--AbstractList抽象类(三)
- java-abstract(抽象类)
- c++中抽象类、虚函数和纯虚函数的学习以及和Java的对比
- java学习日记_44:面向对象之接口与抽象类的区别