匿名内部类也就是没有名字的内部类, 正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写, 但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口。 实例1:不使用匿名内部类来实现抽象方法 运行结果:eat something 可以看到,我们用Child继承了Person类,然 ...
分类:
编程语言 时间:
2016-05-31 18:52:45
阅读次数:
149
*******************************class animal(object): def __init__(self): self.is_handsome=True def eat(self): if self.is_handsome: print "eat...." els ...
分类:
其他好文 时间:
2016-05-31 12:28:57
阅读次数:
205
版本2.5 功能:添加“血块”步骤: 1)添加blood类 2)添加必要的方法:eat方法等 3)让blood对象固定轨迹运动, 并在一定时间后消失 具体代码实现: 新增的blood类: Explode: 1 import java.awt.*; 2 3 public class Explode { ...
分类:
其他好文 时间:
2016-05-26 21:58:34
阅读次数:
362
##javaScript对象 创建简单对象:<br> eg:<br> 没有类的概念,表示对象通过function来表示 <code> function Dog(name,age){ //浏览器会产生一个对象object this.name=name; this.age=age; this.eat=f ...
分类:
编程语言 时间:
2016-05-25 21:59:45
阅读次数:
122
一天一道LeetCode系列(一)题目
Given an array of strings, group anagrams together.
For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],
Return:
[
[“ate”, “eat”,”tea”],...
分类:
其他好文 时间:
2016-05-18 19:08:45
阅读次数:
219
参考博客:点我 要点:Java中的普通函数默认为虚函数,因此动态绑定的行为是默认的,而C++必须将方法声明为虚函数(virtual关键字),执行时才会进行动态绑定,详细区别可参考代码以及注释。 代码大致:实现父类 Animal类,包含数据成员 姓名和年龄,以及实现eat方法和informa方法,子类 ...
分类:
编程语言 时间:
2016-05-17 19:43:07
阅读次数:
215
一、什么是AOP
AOP 是Aspect Oriented Programing 的简称,被译为“面向方面编程”。相信看到这个术语,刚接触的人肯定是很难理解的。下面个人就按照自己的理解将其解释下,如果有什么不妥的地方,还请指出~
一般情况下,如果我们的代码出现了很多重复的,比如在 Pig、Horse、Cat 等类中,它们都拥有共同的方法 eat(),run(), 按照软件重构的思想理念...
分类:
其他好文 时间:
2016-05-12 23:52:01
阅读次数:
249
为了提高代码的复用性,降低代码的耦合(组合实现的两种方式) 模式一: 模式二: 1 <?php 2 //组合模式二 3 class Person{ 4 public function eat(){ 5 echo "eat.<br/>"; 6 } 7 } 8 9 trait Drive{ 10 pub ...
分类:
Web程序 时间:
2016-05-08 11:55:04
阅读次数:
254
描述
Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different qualities beans. Meantime, there is only one bean in any 1*1 grid. Now you want to eat the beans and...
分类:
其他好文 时间:
2016-05-08 01:18:31
阅读次数:
180
接下来经过一个例子,对多态问题加深印象:
猫狗案例。
/*
多态练习:猫狗案例
*/
class Animal {
public void eat(){
System.out.println("吃饭");
}
}
class Dog extends Animal {
public void eat() {
System.out.println("狗吃肉");
}
pu...
分类:
编程语言 时间:
2016-05-07 09:36:53
阅读次数:
171