码迷,mamicode.com
首页 > 其他好文 > 详细

this的一个作用 当前对象

时间:2016-07-10 21:43:16      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

class Person{
 String name="小花";
 int age=19;
 void eat(){
  System.out.println("在吃饭");
 }
}
class Student extends Person{
 void study(String name,int age){
  System.out.println(age+"岁"+name+"在学语文");
 }
}
class Student1 extends Person{
 void study(String name,int age){
  System.out.println(this.age+"岁"+this.name+"在学数学");
 }
}

public class text18 {
 public static void main(String[] args){
  Student Str=new Student();
  Student1 str=new Student1();
  Str.study("小明", 17);
  str.study("校长",18);
 }
}

this的一个作用 当前对象

标签:

原文地址:http://www.cnblogs.com/daoxiang1992/p/5658468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!