九 java面向对象程序设计(this关键字)
九 java面向对象程序设计(this关键字)
/**
* 面向对象之四
* this关键字总结
*/
/*this关键字的第一种用法*/
//在方法中调用同类中的方法,这时的this可以省略.
class ThisPointer
{
public void function1()
{
System.out.println("function1 is calling...");
}
public void function2()
{
System.out.println("function2 is calling...");
this.function1();//调用同类中的function1;
//this是指,这个对象的function方法.
}
public void function3()
{
System.out.println("function3 is calling...");
function2();//相当于this.function2().传入的是同一个对象,所以this可以省略.
}
}
/*this关键字的第二种用法*/
//指明类中与方法参数同名的成员变量.
class Pointer
{
private int i;
private String str;
public void function(int i,String str)
{
this.i = i;
this.str = str;
//通过this,将function方法中同名的i,str和成员变量予以区分.
System.out.println("i = " + i + " , " + "str = " + str);
}
}
/*this关键字的第三种用法*/
//作为一个对象,参与到类的方法中
class Container
{
private String name;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
private Components com;
public void addComponents()//在容器中添加部件,
{
//com = new Components(new Container());
//虽然这样写没问题.但表示,在新创建一个部件的同时,又创建一个容器,然后将新部件加到新容器上.
com = new Components(this);
//用this表示这个容器类的对象,所以我们每次产生新部件是,都是加入到这个容器对象上的.
System.out.println(" is loading...");
}
}
class Components
{
private Container c;
public Components(Container c)
{
this.c = c;//部件类的构造方法指明
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
一、编辑Java源文件
=============================================
Hello.java
=============================================
package test;
public class Hello
{
static
{
try
{
//此处即为本地方法所在链接库名
&n ......
A flexible layout configurable with pattern string.
The goal of this class is to format
a LoggingEvent
and return the results as a String. The results depend on the conversion
pattern
.
The conversion pattern is closely related to the conversion pattern of the
printf function in C ......
//create a new Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.newDocument();
//add root Node
Element noteuser = d.createElement("note-users");
d.appendChil ......
八 java面向对象程序设计(构造方法)
/**
* 面向对象之二
* 构造方法(构造机):
*
* 1,构造方法的特征:
* 它具有与类相同的名称;
* 它不含返回值;
* 它不能在方法中用return语句返回一个值
* 注意:在构造方法里不含返回值的概念是不同于“void&rdquo ......