zoukankan
html css js c++ java
学习OO思想
没抓住主线,请指教。
Code
using
System;
namespace
Study
{
public
class
Test
{
static
void
Main(
string
[] args)
{
Son_Class Son
=
new
Son_Class();
Son.CommonMethod();
((Father_Class)Son).CommonMethod();
//
方法二:类型转换
Console.Read();
}
}
abstract
class
Father_Class
//
抽象类才能有抽象方法;不能实例化
{
public
Father_Class(
string
parameter)
{ Console.WriteLine(parameter); }
//
构造函数
public
virtual
void
virtualMethod()
{ Console.WriteLine(
"
Father_Class.virtualMethod
"
); }
public
abstract
void
abstractMethod();
public
void
CommonMethod()
{ Console.WriteLine(
"
Father_Class.CommonMethod
"
); }
}
class
Son_Class : Father_Class
{
public
Son_Class() :
base
(
"
子类给基类通信的方法:用base调用基类的构造函数
"
)
{ }
public
sealed
override
void
virtualMethod()
{ Console.WriteLine(
"
Son_Class.virtualMethod ; sealed override方法已经不能在孙类override
"
); }
public
override
void
abstractMethod()
{ Console.WriteLine(
"
Son_Class.abstractMethod
"
); }
public
new
void
CommonMethod()
{
Console.WriteLine(
"
Son_Class.CommonMethod
"
);
base
.CommonMethod();
//
方法一
}
}
}
/**/
/*
继承:实现功能扩展和复用
* virtual可以自己实现,也可以由子类override;abstract只能由子类override;用new可以任意重写一个父类的同名方法(不用new只会警告)
* sealed类可以防止被继承;子类中sealed override的方法可以防止被孙类override
* 子类给基类通信的方法:用base调用基类的构造函数
* 子类中访问基类被override成员的方法:
封装:
多态:
* 编译时多态:重载;运行时多态的实现:接口、继承、抽象类
易混概念:
* 接口用于定义类的能力(多用able结尾);抽象类是能提供部分实现的接口,多用于定义属性,如版本控制;C#的派生类只能从一个类中继承,只能通过接口实现多重继承
* static = share,用类访问并被类的所有实例共享,避免冗余,如sqlconstr
*/
查看全文
相关阅读:
汉诺塔
协变和逆变随笔
NetCore开发第一步 Log4Net日志引入
插入排序算法
选择排序算法
冒泡排序算法
排序算法
线性链表
SAN
SAM -- Chap 8 提升方法 自我梳理
原文地址:https://www.cnblogs.com/hbreset/p/1345887.html
最新文章
vs2019 缺少add-migration命令
“Microsoft visual c++2019 X64 Minimum Runtime 需要修复”的解决方法
.net core 发布到IIs运行错误解决方案
AddTransient AddScoped AddSingleton的区别
CancellationTokenSource (取消令牌)
.NET Framework迁移到.NET Core方案
C# await Task.Yield();
ASP.NET / C# / CODING / SERVERS & SERVICES / WEB Unable to launch the IIS Express Web server error on Visual Studio 2019 – How to fix it
vs利用本地代码调试微信公众号开发接口
逆向.面向监狱编程(一)工具篇:初识IDA
热门文章
将vim打造为强大的IDE
剑指Offer32-Ⅱ从上到下按层打印二叉树,同一层的节点按从左到右的顺序打印,每一层打印到一行。
Java快速排序
Java中的Queue接口
AOP中实现动态代理的两种方式
Java中的位运算
在IDEA中dollar符号$在html中不能识别
BlockingQueueConsumer$DeclarationException: Failed to declare queue(s):xxxx;创建队列异常
学习商城秒杀项目有感
项目运行找不到服务
Copyright © 2011-2022 走看看