Java抽象类与接口的区别
抽象类 接口 抽象类与接口区别 1.抽象类 抽象类用abstract来修饰,例如: package com.test.abstractaaa; public abstract class TestAbstract { } 抽象类是用来捕捉子类的通用性的,它不能被实例化,只能用作子类的超类,抽象类是被用来创建继承层级里子类的模板,例如JDK中的GenericServlet类中部分代码: public abstract class GenericServlet implements Servlet, ServletConfig, java.io.Serializable{ public void init(ServletConfig config) throws ServletException { this.config = config; this.init(); } public void init() throws ServletException {} public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOException; public void destroy() {} }