java中抽象类和抽象方法到底什么关系?请举例说明!
2014-08-21 10:40
731 查看
抽象类和抽象方法什么关系?抽象类中可能有抽象方法,也可能没有抽象方法。那位说,就跟没说一样,那抽象类和抽象方法都叫抽象,他们必定有关系,那关系是什么呢?如果一个类中有抽象方法,它必须得是抽象类。
An abstract class may have no abstract method,such as the following class Car.
马 克- t o --wi n: At this time,the only point and the meaning of abstract class is that we can not instantiated the class, because it is abstract class.Why an abstract class can have a nonabstract method? what is the point? also in logic, think over the following
example, car is a bit abstract in that you dont' know exactly whether it is a truck or a jeep or a limersine, 马克-to-win:so it is defined as a abstract class. but no matter whether it is truck,jep, or limersine, it definitely use steering wheel. so its steer()
method is an ordinary method instead of an abstract method. ) Abstract class can’t be instantiated.
例1.7.1
abstract class Nothing {//里面有方法也照样声明为abstract
void nothing() {
System.out.println("nothing");
}
}
abstract class VehMark_to_win {
abstract void steer();
abstract void move();
}
class Bike extends VehMark_to_win {//Bike不是抽象的, 所以必须得全部实现abstract方法
。。。。。。。。。。。。。。。
详情请见:http://www.mark-to-win.com/JavaBeginner/JavaBeginner3_web.html#RelationAbstractMethodClass
An abstract class may have no abstract method,such as the following class Car.
马 克- t o --wi n: At this time,the only point and the meaning of abstract class is that we can not instantiated the class, because it is abstract class.Why an abstract class can have a nonabstract method? what is the point? also in logic, think over the following
example, car is a bit abstract in that you dont' know exactly whether it is a truck or a jeep or a limersine, 马克-to-win:so it is defined as a abstract class. but no matter whether it is truck,jep, or limersine, it definitely use steering wheel. so its steer()
method is an ordinary method instead of an abstract method. ) Abstract class can’t be instantiated.
例1.7.1
abstract class Nothing {//里面有方法也照样声明为abstract
void nothing() {
System.out.println("nothing");
}
}
abstract class VehMark_to_win {
abstract void steer();
abstract void move();
}
class Bike extends VehMark_to_win {//Bike不是抽象的, 所以必须得全部实现abstract方法
。。。。。。。。。。。。。。。
详情请见:http://www.mark-to-win.com/JavaBeginner/JavaBeginner3_web.html#RelationAbstractMethodClass
相关文章推荐
- java中downcast向下转型到底有什么用? 举例说明!
- java中Super到底是什么意思?必须举例说明!
- java中Super到底是什么意思?必须举例说明!
- java中hashCode和equals什么关系,hashCode到底怎么用的
- 举例说明java面向对象思想的体现:抽象类、接口
- java中抽象类和抽象方法到底有什么用呢?
- java中Arrays有什么用,举例说明?
- java中Iterator有什么用,举例说明?
- java中接口和抽象类有什么区别,举例!
- java中TreeMap有什么用,举例说明?
- 使用设计模式,到底有什么好处?举例说明
- java开发线程篇3:同步和异步有何异同,在什么情况下分别使用他们?举例说明。
- java中异常到底有什么用?举例
- 【Java面试题】25 同步和异步有何异同,在什么情况下分别使用他们?举例说明。
- java中HashSet有什么用,举例说明?
- java中的工厂模式是什么,请举例说明
- java中的抽象函数是什么? 和抽象类是什么关系? 抽象类是什么?又什么作用?
- java中方法重载是什么, 实际中到底有什么意义, 用处?请举例
- java中ArrayList有什么用,举例说明?
- 举例说明什么是JAVA序列化