附录A培训实习生-面向对象基础类和实例(1)
2014-08-14 20:52
288 查看
对象是一个自包含的实体,用一组可识别的特性和行为来标识.
面向对象编程,Object-Oriented Programming,其实就是针对对象进行编程的意思.
类就是具有相同属性和功能的对象的抽象的集合.
在编程过程中注意:
第一,类名称首字母记着要大写.多个单词则各个首字母大写.
第二,对外公开的方法需要用public修饰符.
实例,就是一个真实的对象.
实例化就是创建对象的过程,使用new关键字来创建.
下面是一个例子:
这是一个类,
调用这个类,
面向对象编程,Object-Oriented Programming,其实就是针对对象进行编程的意思.
类就是具有相同属性和功能的对象的抽象的集合.
在编程过程中注意:
第一,类名称首字母记着要大写.多个单词则各个首字母大写.
第二,对外公开的方法需要用public修饰符.
实例,就是一个真实的对象.
实例化就是创建对象的过程,使用new关键字来创建.
下面是一个例子:
这是一个类,
using System; using System.Collections.Generic; using System.Text; namespace AnimalGames { class Cat { public string Shout() { return "瞄"; } } }
调用这个类,
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace AnimalGames { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Cat cat = new Cat();//将cat实例化 //注意:Cat cat = new Cat();其实做了两件事, //Cat cat;声明一个Cat的对象,对象名是cat //cat = new Cat();将此cat对象实例化 MessageBox.Show(cat.Shout()); } } }
相关文章推荐
- 附录A培训实习生-面向对象基础构造方法和带参数的构造方法(2)
- 附录A培训实习生-面向对象基础方法重载(3)
- 培训实习生-----面向对象基础
- C# 在线培训之零基础入门 06:面向对象入门
- C# 培训之零基础入门 07:打老鼠之面向对象重构
- 传智播客.Net培训—C#面向对象基础
- PHP面向对象开发基础与实例
- C#面向对象基础(四) 静态成员与实例成员
- PHP面向对象基础实例
- 第二章 实例研究:设计一个文档编辑器--《设计模式-可复用面向对象软件的基础》Erich Gamma
- 大话设计模式 附录A 面向对象基础 C++实现
- java基础学习05(面向对象基础01--类实例分析)
- 《面向对象基础:C++实现》学习笔记之一
- Javascript面向对象程序设计培训回顾
- 第一章 面向对象基础
- 《面向对象基础:C++实现》学习笔记之七
- 面向对象设计与分析培训(含PPT)
- GIS学习之面向对象基础
- 设计模式 可复用面向对象软件的基础(概念你认识多少)
- Design Patterns(设计模式 可复用面向对象软件的基础)