abstrcat class 与 interface

abstrcat class 单一继承;包含方法,属性,变量等;抽象方法需全部实现 重写。

interface 可多继承;只包含方法声明,不包含实现;全部接口方法须实现。

 

class Program
{
static void Main(string[] args)
{
var t1 = new TestClass();
//abstract
Console.WriteLine("---------1-------------");
Console.WriteLine(t1.abstractInt2);
Console.WriteLine("---------2-------------");
t1.abstractInt2 = 110;
Console.WriteLine(t1.abstractInt2);
Console.WriteLine("---------3-------------");
t1.TestAbstract1();
//interface
Console.WriteLine("---------4-------------");
t1.GetInterface1();
Console.WriteLine("---------5-------------");
Console.WriteLine(t1.GetInterface2());
}
}

abstract class AbstractClass
{
int abstractInt1 = 0;
public int abstractInt2 { get; set; }

public void testAbstract2()
{
Console.WriteLine("In testAbstract2");
}
public int getTestInt2()
{
return abstractInt2;
}
public abstract void TestAbstract1();
}
interface TestInterface
{
void GetInterface1();
string GetInterface2();
}
class TestClass : AbstractClass, TestInterface
{
public override void TestAbstract1()
{
Console.WriteLine("TestClass In testAbstract1" + abstractInt2);
}

public void GetInterface1()
{
Console.WriteLine("In Interface1");
}

public string GetInterface2()
{
return "getInterface2" + abstractInt2;
}
}

 

小技巧

 

显示接口  就是+PUBLIC 供外部调用

 

posted @ 2017-10-04 09:28  007008aabb  阅读(202)  评论(0编辑  收藏  举报