2011年12月1日

this

摘要: 如果一个类中有多个构造方法,也可以利用this关键字互相调用。例子(如何使用this调用属性):package test;class Person { private String name; private int age; public Person() { // 无参构造 System.out.println("一个新的Person对象被实例化。"); } public Person(String name, int age) { this(); // 在此处调用Person类中的无参构造方法 this.name = name; // 为name属性赋值 this.a 阅读全文

posted @ 2011-12-01 15:11 wangbokun 阅读(218) 评论(0) 推荐(0) 编辑

String

摘要: this关键字最大的作用就是让类中的一个方法,访问该类中的另一个方法或属性,例如:有一个Dog类, 这个dog对象的run方法丈调用他的jump方法。实例化String对象public class Student { public static void main(String [] args) {// String name="wbk"; String name=new String("wbk"); System.out.println("姓名:"+name); }} 而两次运行的结果是一样的,姓名:wbk2.string的内容的比 阅读全文

posted @ 2011-12-01 11:34 wangbokun 阅读(208) 评论(0) 推荐(0) 编辑

导航