读书笔记(第九讲)Encapsulation
来源:互联网 发布:北京全景视觉网络侵权 编辑:程序博客网 时间:2024/06/04 18:46
面向对象程序设计的三大基本特征,相信学过面向对象程序的人都应该知道:封装encapsulation,继承inheritence,多态polymorphism
这节主要讲解一下encapsulation的基本用法.
何谓encapsulation?简单的讲就是将property & method 放到一个class中,就简单的叫做encapsulation
从这个所谓的定义中,我们应该define class
怎么样定义一个类呢?eg:public class Person{}
如何使用类中的property & method?首先要先创建 Object.eg:Person person = new Person();
public class Test2
{
public int add(int a,int b)
{
return a+b;
}
public int subtract(int a,int b)
{
return a-b;
}
public int multiply(int a,int b)
{
return a*b;
}
public int divide(int a,int b)
{
return a/b;
}
public void output()
{
System.out.println("Hello World");
}
执行结果:C:\lesson0>java Test2
7
-1
12
0
Hello World
- 读书笔记(第九讲)Encapsulation
- 读书笔记(第十讲)Encapsulation
- 读书笔记(第十一讲)Encapsulation
- Oracle(第九讲)
- 读书笔记(第一讲)
- 读书笔记(第五讲)
- 读书笔记(第七讲)
- 第九讲
- 第九讲
- 第九讲
- 封装(Encapsulation)、
- encapsulation
- 第九讲 设定字体(一)
- 第九讲:用户界面 View(四)
- 读书笔记(第四讲)operator
- 读书笔记(第八讲)OOP
- 读书笔记(第十二~十五讲)
- 读书笔记(第十六讲)OVERLOAD
- extern,static存储空间矛盾
- Deployment failure on Tomcat 6.x. Could not copy all resources to
- 图片下载
- 操作系统 进程/线程 同步与互斥
- OpenSessionInViewFilter 说明与配置
- 读书笔记(第九讲)Encapsulation
- 学习apache commons-io类库中的文件清除器
- 悬浮的文字效果
- 十六进制数字组成的字符串的程序&库函数strtoul()
- ASP FSO文件操作
- 变换坐标系的函数——glLoadIdentity()与glTranslatef()和glRotatef()
- Tomcat web.xml配置文件
- internet explorer已阻止此站点用不安全方式使用ActiveX控件
- 美国网站在中国失败的10大思路性执行错误