vala 接口示例代码
代码语言:vala
所属分类:其他
代码描述:vala 接口示例代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
/* This example gives you a simple interface, Speaker, with - one abstract method, speak It shows you three classes to demonstrate how these and overriding them behaves: - Fox, implementing Speaker - ArcticFox, extending Fox AND implementing Speaker (ArcticFox.speak () replaces superclasses' .speak()) - RedFox, extending Fox BUT NOT implementing speaker (RedFox.speak () does not replace superclasses' .speak()) Important notes: - generally an object uses the most specific class's implementation - ArcticFox extends Fox (which implements Speaker) and implements Speaker itself, - ArcticFox defines speak () with new, so even casting to Fox or Speaker still gives you ArcticFox.speak () - RedFox extends from Fox, but DOES NOT implement Speaker - RedFox speak () gives you RedFox.speak () - casting RedFox to Speaker or Fox gives you Fox.speak () */ /* Speaker: extends from GObject */ interface Speaker : Object { /* speak: abstract without a body */ public abstract void speak (); } /* Fox: implements Speaker, implements speak () */ class Fox : Object, Speaker { public void speak () { stdout.printf (" Fox says Ow-wow-wow-wow\n"); } } /* ArcticFox: extends Fox; must also implement Speaker to re-define * inherited methods and use them as Speaker */ class ArcticFox : Fox, Speaker { /* speak: uses 'new' to replace speak () from Fox */ public new void speak () { stdout.printf (" ArcticFox says Hate.........完整代码请登录后点击上方下载按钮下载查看
网友评论0