⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10.4.1.htm

📁 建立《编译原理网络课程》的目的不仅使学生掌握构造编译程序的原理和技术
💻 HTM
字号:
<html>

<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>

<body>

<table align="right" width="300">
  <tr>
    <td>
    <img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='10.3.1b.htm'" ></td>
    <td>
    <img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='10.5.1.htm'" ></imag></td>
  </tr>
</table>

<p> </p>

<font class="title2"><b>10.4 私有属性和方法的编译</b></font>
<p></p>
<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content">
<p>
真正的面向对象语言能够为对象的属性提供保护,防止其它对象的方法直接操作它们。私有属性是指禁止从不属于该对象的函数中读取或访问的属性;私有方法是指不能从对象外部调用的方法。
</p>
<p>
保证私有性可以在编译的类型检查阶段完成。以程序10.5为例,在类C的符号表中,可以为每一个属性和方法提供一个布尔量,用来标识该属性或方法是否有私有性。这样当编译表达式c.f()或c.x时,我们可以察看相应的布尔变量,并拒绝从对象声明以外的函数中访问私有属性和方法。
</p>
<p>
不同的语言允许不同的私有性和保护,包括:
</p>
<p>
·属性和方法只能从声明它们的类中访问。
</p>
<p>
·属性和方法只能从声明它们的类和该类的任何子类中访问。
</p>
<p>
·属性和方法只能从与声明它们的类位于相同的模块(包,名字空间)访问。
</p>
<p>
·属性在声明它们的类外部是只读的,只能被该类的方法修改。
</p>
</td></tr></table>
<p> </p>

<table align="right" width="300">
  <tr>
    <td>
    <img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='10.3.1b.htm'" ></td>
    <td>
    <img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'"
    onclick="vbscript:window.location.href='10.5.1.htm'" ></imag></td>
  </tr>
</table>
</body>
</html>
<html><script language="JavaScript">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -