ColdFusion中的继承体现在CFCs,用法就是在<cfcomponent>中加入属性extends,简单的说,sub.cfc通过继承parent.cfc,就自动拥有了parent.cfc中的(constructor构造器中的)变量、属性和公开的(public)方法,比如:
<!--- parent.cfc --->
<cfcomponent>
<cffunction name="getSth">
<cfreturn "this is parent class">
</cffunction>
</cfcomponent>
<!--- sub.cfc --->
<cfcomponent extends="parent">
<cffunction name="getSthFromParent">
<cfreturn super.getSth()>
</cffunction>
</cfcomponent>
<!--- test.cfm --->
<cfset Obj = createObject("component", "sub")>
<cfset temp = Obj.getSthFromParent()>
<cfoutput>#temp#</cfoutput>
test.cfm将输出:“this is parent class”