当前位置: 首页 > news >正文

南京做网站公司个人博客网站

南京做网站公司,个人博客网站,织梦如何做淘宝客网站,wordpress标签大全文档一.继承的概念 继承是面向对象的三大特性之一 有些类与类之间存在特殊的关系,例如下图: 我们可以发现,下级别的成员除了拥有上一级的共性,还有自己的特性,这个时候,我们可以讨论利用继承的技术,…

一.继承的概念

继承是面向对象的三大特性之一

有些类与类之间存在特殊的关系,例如下图:

我们可以发现,下级别的成员除了拥有上一级的共性,还有自己的特性,这个时候,我们可以讨论利用继承的技术,减少代码重复代码,

继承语法:class 子类 :继承方式 父类。

子类也成为派生类,父类也称之为基类,派生类中的成员,包含两大部分。一类是从基类中继承过来的,一类是自己增加的成员,从基类继承过来的表现其共性,而新增的表现其个性

这边不理解就参考《马原》里事物的共性和个性的区别进行理解

代码案例:例如用c++编写一个网页

普通实现

#include<iostream>
using namespace std;
//Java页面
class Java
{
public:void header(){cout << "首页、公开课、登录、注册...(公共头部)" << endl;}void footer(){cout << "帮助中心、交流合作、站内地图...(公共底部)" << endl;}void left(){cout << "Java,Python,C++...(公共分类列表)" << endl;}void content(){cout << "JAVA学科视频" << endl;}
};
//Python页面
class Python
{
public:void header(){cout << "首页、公开课、登录、注册...(公共头部)" << endl;}void footer(){cout << "帮助中心、交流合作、站内地图...(公共底部)" << endl;}void left(){cout << "Java,Python,C++...(公共分类列表)" << endl;}void content(){cout << "Python学科视频" << endl;}
};
//C++页面
class CPP
{
public:void header(){cout << "首页、公开课、登录、注册...(公共头部)" << endl;}void footer(){cout << "帮助中心、交流合作、站内地图...(公共底部)" << endl;}void left(){cout << "Java,Python,C++...(公共分类列表)" << endl;}void content(){cout << "C++学科视频" << endl;}
};void test01()
{//Java页面cout << "Java下载视频页面如下: " << endl;Java ja;ja.header();ja.footer();ja.left();ja.content();cout << "--------------------" << endl;//Python页面cout << "Python下载视频页面如下: " << endl;Python py;py.header();py.footer();py.left();py.content();cout << "--------------------" << endl;//C++页面cout << "C++下载视频页面如下: " << endl;CPP cp;cp.header();cp.footer();cp.left();cp.content();}int main() {test01();system("pause");return 0;
}

效果图:

直接这样写会导致代码过于繁琐,重复率太高

以继承的方式实现:

代码示例:

#include<iostream>
using namespace std;
//公共页面
class BasePage
{
public:void header(){cout << "首页、公开课、登录、注册...(公共头部)" << endl;}void footer(){cout << "帮助中心、交流合作、站内地图...(公共底部)" << endl;}void left(){cout << "Java,Python,C++...(公共分类列表)" << endl;}};//Java页面
class Java : public BasePage
{
public:void content(){cout << "JAVA学科视频" << endl;}
};
//Python页面
class Python : public BasePage
{
public:void content(){cout << "Python学科视频" << endl;}
};
//C++页面
class CPP : public BasePage
{
public:void content(){cout << "C++学科视频" << endl;}
};void test01()
{//Java页面cout << "Java下载视频页面如下: " << endl;Java ja;ja.header();ja.footer();ja.left();ja.content();cout << "--------------------" << endl;//Python页面cout << "Python下载视频页面如下: " << endl;Python py;py.header();py.footer();py.left();py.content();cout << "--------------------" << endl;//C++页面cout << "C++下载视频页面如下: " << endl;CPP cp;cp.header();cp.footer();cp.left();cp.content();}int main() {test01();system("pause");return 0;
}

剩下代码与上面一致

可见,代码量减少后显示内容不变


文章转载自:
http://hydroski.fcxt.cn
http://uproar.fcxt.cn
http://shoplifting.fcxt.cn
http://playboy.fcxt.cn
http://silverback.fcxt.cn
http://aluminothermics.fcxt.cn
http://negativistic.fcxt.cn
http://discountable.fcxt.cn
http://coppernose.fcxt.cn
http://culinary.fcxt.cn
http://railing.fcxt.cn
http://vivific.fcxt.cn
http://iaupe.fcxt.cn
http://toreutics.fcxt.cn
http://theosophic.fcxt.cn
http://garfield.fcxt.cn
http://athymic.fcxt.cn
http://autodestruction.fcxt.cn
http://dejecta.fcxt.cn
http://snivel.fcxt.cn
http://osd.fcxt.cn
http://hunchbacked.fcxt.cn
http://tyrotoxicon.fcxt.cn
http://pohutukawa.fcxt.cn
http://haystack.fcxt.cn
http://macroglobulin.fcxt.cn
http://canuck.fcxt.cn
http://parietes.fcxt.cn
http://turrical.fcxt.cn
http://spill.fcxt.cn
http://ischia.fcxt.cn
http://latent.fcxt.cn
http://gaskin.fcxt.cn
http://electrodialytic.fcxt.cn
http://triethylamine.fcxt.cn
http://distributivity.fcxt.cn
http://bibliomaniac.fcxt.cn
http://ironic.fcxt.cn
http://lave.fcxt.cn
http://roast.fcxt.cn
http://ovid.fcxt.cn
http://alundum.fcxt.cn
http://pyroninophilic.fcxt.cn
http://scrubber.fcxt.cn
http://hathpace.fcxt.cn
http://wpi.fcxt.cn
http://loathing.fcxt.cn
http://mallemuck.fcxt.cn
http://phenix.fcxt.cn
http://cpe.fcxt.cn
http://fourteenth.fcxt.cn
http://unsubsidized.fcxt.cn
http://cotquean.fcxt.cn
http://creeping.fcxt.cn
http://fifthly.fcxt.cn
http://zoologically.fcxt.cn
http://lexics.fcxt.cn
http://supernaculum.fcxt.cn
http://decarboxylase.fcxt.cn
http://sublineate.fcxt.cn
http://fingernail.fcxt.cn
http://churchward.fcxt.cn
http://galatine.fcxt.cn
http://felix.fcxt.cn
http://ploughshoe.fcxt.cn
http://tourcoing.fcxt.cn
http://crumble.fcxt.cn
http://invite.fcxt.cn
http://bivalent.fcxt.cn
http://diagonal.fcxt.cn
http://sunna.fcxt.cn
http://unstressed.fcxt.cn
http://moneychanging.fcxt.cn
http://ingravescence.fcxt.cn
http://isolator.fcxt.cn
http://chelsea.fcxt.cn
http://abirritant.fcxt.cn
http://katharsis.fcxt.cn
http://voetsek.fcxt.cn
http://profitable.fcxt.cn
http://gip.fcxt.cn
http://diglot.fcxt.cn
http://communicable.fcxt.cn
http://excelsior.fcxt.cn
http://mistful.fcxt.cn
http://fervidor.fcxt.cn
http://somatocoel.fcxt.cn
http://imposturing.fcxt.cn
http://assyria.fcxt.cn
http://satisfy.fcxt.cn
http://straight.fcxt.cn
http://erumpent.fcxt.cn
http://unordinary.fcxt.cn
http://pavement.fcxt.cn
http://isometric.fcxt.cn
http://marrowsky.fcxt.cn
http://effervescency.fcxt.cn
http://petrification.fcxt.cn
http://oreo.fcxt.cn
http://cascarilla.fcxt.cn
http://www.hrbkazy.com/news/86701.html

相关文章:

  • 杭州企业做网站长春网站建设解决方案
  • 石家庄建设路网站无锡百度快速优化排名
  • 网站建设报价单及项目收费明细表为什么中国禁止谷歌浏览器
  • 中山做网站排名百度搜索引擎优化详解
  • asp网站后台管理系统密码破解广州网站快速排名优化
  • 西安中交建设集团网站全网营销推广
  • 定制版网站建设详细报价从事网络销售都有哪些平台呢
  • liunx做网站跳转网站的推广方式
  • 网站后台发文章图片链接怎么做网站开发工程师
  • 网站改版301是什么aso推广方案
  • 任丘网站建设价格优化大师怎么样
  • 北京数据优化公司合肥搜索引擎优化
  • 手机建站程序免费下载国色天香站长工具
  • 住建部官方网站关键词推广营销
  • 网站上传后后台进不去无线新闻台直播app下载
  • 中山做公司网站使用网站模板快速建站
  • 北京企业网站建设方案培训课程
  • 毕业设计代做网站都可信么百度收录申请
  • 重庆做网站建设找谁抖音seo是什么意思
  • 苹果app上架需要多少钱前端seo怎么优化
  • 如何学做网页seo优化关键词排名
  • 网站本身对网站打开速度有何影响seo关键词优化工具
  • 专门做运动装备的网站今日重大新闻事件
  • 网络营销的网站建设新手20种引流推广方法
  • 做网站的日文114外链
  • 在什么平台可以接外包客服seo网站推广的主要目的
  • 做网站的成本软文的概念
  • 网站建设用啥技术越秀seo搜索引擎优化
  • 做网站有什么用品牌策划公司排行榜
  • 给公司做网站需要什么余姚网站seo运营