?java——this用法:(无法从静态上下文引用this

2019年2月16日23:33:09 发表评论 1,124 views

this表示当前对象,所谓当前对象,就是调用类中属性或方法的那个对象。

/**
 * Created by xabcd on 2019/2/16.
 */
public class total_this
{
    class total{
        private String name;
        private int age;
        public void total(String name,int age)
        {
            this.name = name;
            this.age = age;
        }
        public String talk()
        {
            return "我是:"+this.name+"今年"+this.age+"岁";
        }

    }
    public static void main(String args[])
    {
        total t = new total("张三", 33);
        System.out.println(t.talk());
    }

}

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: