[Quote=引用 2 楼 Sandy945 的回复:] a b = new c(); 如果a 是类 那c就是子类 如果a 是接口 那c就是实现类 b是a的实例 [/Quote up
up up 就是个继承关系的.
a 是父类,c是子类 b是对象名
好像是受谭老害的……b是变量名。a和c都是类,a是c的基类,c是a的派生类。
a b = new c(); 如果a 是类 那c就是子类 如果a 是接口 那c就是实现类 b是a的实例 也就是父类的引用指向子类的对象!
//这是一个接口实现的动物喂养的小实例,望楼主能够明白! using System; using System.Collections.Generic; using System.Text;namespace AbstractAnimalDemo { public interface IFeedable//定义一个接口 { void eat(); } } ---------------------------------------------------- using System; using System.Collections.Generic; using System.Text;namespace AbstractAnimalDemo { class Lion:IFeedable { #region IFeedable 成员 public void eat() { Console.WriteLine("狮子吃肉"); } #endregion } } ------------------------------------- using System; using System.Collections.Generic; using System.Text;namespace AbstractAnimalDemo { class Monkey:IFeedable { #region IFeedable 成员 public void eat() { Console.WriteLine("猴子吃香蕉!"); } #endregion } }
using System; using System.Collections.Generic; using System.Text;namespace AbstractAnimalDemo { class Program { static void Main(string[] args) { IFeedable f1 = new Monkey(); f1.eat(); IFeedable f2 = new Lion(); f2.eat(); } }
a 代表的是类a,
b 代表的是类a的一个引用,
new c()的意思是实例化类c的对象
a和c是继承关系。哎 也不知道解释的对不对。
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
b是a的实例
IList<string>() obj=new List<string>()
所以可以用b = new c();
c为实现了b中方法的类;
所以bc不相同
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
父类的指针指向子类的实例
a b = new c();
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
前提是c必须继承自a
b是a的实例
http://msdn.microsoft.com/zh-cn/dd368002.aspx看看这个你应该可以明白!
a b = new c();
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
b是a的实例
[/Quote
up
up up 就是个继承关系的.
b是对象名
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
b是a的实例 也就是父类的引用指向子类的对象!
using System;
using System.Collections.Generic;
using System.Text;namespace AbstractAnimalDemo
{
public interface IFeedable//定义一个接口
{
void eat();
}
}
----------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;namespace AbstractAnimalDemo
{
class Lion:IFeedable
{
#region IFeedable 成员 public void eat()
{
Console.WriteLine("狮子吃肉");
} #endregion
}
}
-------------------------------------
using System;
using System.Collections.Generic;
using System.Text;namespace AbstractAnimalDemo
{
class Monkey:IFeedable
{
#region IFeedable 成员
public void eat()
{
Console.WriteLine("猴子吃香蕉!");
} #endregion
}
}
using System;
using System.Collections.Generic;
using System.Text;namespace AbstractAnimalDemo
{
class Program
{
static void Main(string[] args)
{
IFeedable f1 = new Monkey();
f1.eat();
IFeedable f2 = new Lion();
f2.eat();
}
}
b是c的一个实例化对象
如:
Prosen stu =new Student();
Prosen 就是a Student是c stu是b
a b = new c();
如果a 是类 那c就是子类
如果a 是接口 那c就是实现类
b是a的实例
正解