如果要修该一个类中的某个方法一共有三种方法:继承,写一个装饰类,动态代理
这里我主要介绍装饰类:
1.写一个interface Animal
package com.itheima.pool;
public interface Animal {
public void eat();
public void bite();
}
2.写一个Dog类继承Animal接口:
pack...
分类:
其他好文 时间:
2015-07-02 10:19:54
阅读次数:
117
直接上代码 代码里面有注释 1 #import 2 3 @interface Animal : NSObject 4 //类方法使用 “+”开头 不带参数的 5 +(void)eat; 6 7 +(void)eat02:(NSString *)name; 8 9 @end10 11 12 @...
分类:
其他好文 时间:
2015-07-01 17:46:45
阅读次数:
115
1 #include 2 #include 3 using namespace std; 4 5 class Animal{ 6 public: 7 Animal(string name) : name(name){} 8 void printName(){ 9 ...
分类:
其他好文 时间:
2015-06-27 11:25:45
阅读次数:
101
1. 定义 Animal 类 public class Animal{ } 定义 Dog类,继承 Animal public class Dog : Animal{ }2. 变量是一个标签,对象是实际存在的东西,赋值号"="就是贴标签的过程 Dog dog = new Dog(); //...
分类:
其他好文 时间:
2015-06-25 00:04:03
阅读次数:
130
/// 静态全局变量 :只能在当前cpp中访问到static int s_global = 0;void funcA() { /// 静态局部变量 (函数静态变量) 初始化过一次就不会被覆盖 static int s_funcValue = 1;}class Animal {public: ...
分类:
编程语言 时间:
2015-06-23 21:27:44
阅读次数:
160
//// Dog.h// OC2-重写//// Created by qianfeng on 15/6/17.// Copyright (c) 2015年 qianfeng. All rights reserved.//#import "Animal.h"@interface Dog : A...
分类:
其他好文 时间:
2015-06-17 15:07:54
阅读次数:
85
//// Cat.h// OC3-父类指针指向子类对象//// Created by qianfeng on 15/6/17.// Copyright (c) 2015年 qianfeng. All rights reserved.//#import "Animal.h"@interface...
分类:
其他好文 时间:
2015-06-17 14:55:44
阅读次数:
95
1、考虑下面的需求,把一组类型不同,但是相互关联的对象放入容器中,比如Animal,Dog,Cat对象。2、容器只能包含一组 类型相同的对象,Animal,Dog,Cat对象是没有办法放入容器中的。3、怎么解决上面的问题? 假设容器为vector,可以使用vector,这会导致一个新问题,因为v.....
分类:
编程语言 时间:
2015-06-14 21:11:59
阅读次数:
141
publicclassArrayTest{
publicstaticvoidmain(String[]args)
{
Animal[]a=newAnimal[3];
Dogd1=newDog();
Dogd2=newDog();
Catc1=newCat();
Catc2=newCat();
a[0]=d1;
a[1]=d2;
a[2]=c1;
a[3]=c2;
//需求:遍历数组,取出每一个对象,如果是Dog,执行eat方法,如果是Cat,执行m..
分类:
编程语言 时间:
2015-06-14 16:53:40
阅读次数:
148
1、纯虚方法解决什么样的问题,为什么要设计出纯虚方法? 考虑下面的需求,基类声明了一个方法,这个方法只针对具体的子类才有意义,比如Animal的Eat()方法,调用Animal的Eat方法是没有意义的。比如Dog吃肉,Cat吃鱼,而Animal吃什么呢,没有意义。2、既然Animal调用Eat没有意...
分类:
编程语言 时间:
2015-06-12 23:38:38
阅读次数:
190