正在加载图片...
this引用 类的成员方法中访问类的成员变量,可以 使用关键字this指明要操作的对象 在类方法中,Java自动用this关键字把所有变量 和方法引用结合在一起。t的使用是不必要的, 程序中可以不写该关键字 有些情况下关键th是 命/ public class Date{ private int day, month, year public void print Date( System. out. println("The current date is(dd/mm /yy) this day +/+this month +" /+this year)this引用 ▪ 类的成员方法中访问类的成员变量,可以 使用关键字this指明要操作的对象 ▪ 在类方法中,Java自动用this关键字把所有变量 和方法引用结合在一起。this的使用是不必要的, 程序中可以不写该关键字 ▪ 有些情况下关键字this是必需的 ▪ 例如,在完全独立的类中调用一个方法,同时 把对象实例作为一个自变量来传送。此时,要 用this指明对哪个对象实例进行操作 ▪ Birthday bDay = new Birthday (this); public class Date { private int day, month, year; public void printDate() { System.out.println("The current date is (dd / mm / yy): " + this.day + " / " + this.month + " / " + this.year); } }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有