第八章前四部分

2018.11.23  星期五

1.接口

package 例题;

public class Person1
{
static int count=0;
protected String name;
protected int age;
public Person1(String n1,int a1)
{
name=n1;
age=a1;
this.count++;
}
public String toString()
{
return this.name+","+this.age;
}
public void display()
{
System.out.println("本类名="+this.getClass().getName()+";");
System.out.println("父类名="+this.getClass().getSuperclass().getName());
System.out.println("Person.count="+this.count+" ");
System.out.print("Student.count="+Student.count+" ");
Object obj=this;
if(obj instanceof Student)
System.out.println(obj.toString()+"是Student类对象");
else if(obj instanceof Person1)
System.out.println(obj.toString()+"是Person1类对象");
}
}
class Student extends Person1
{
static int count=0;
protected String dept;
protected Student(String n1,int a1,String d1)
{
super(n1,a1);
dept=d1;
this.count++;
}
public String toString()
{
return super.toString()+","+dept;
}
public void display()
{
super.display();
System.out.println("super.count="+super.count);
System.out.println(" ;this.count="+this.count);
}

public static void main(String[]args)
{
Person1 per=new Person1("王永涛",23);
per.display();
Student stu=new Student("张三",22,"计算机");
stu.display();
}
}

 感悟:这个代码运行时不同于其他的,不是点一下就直接运行的,还需要一步一步的指引,原先以为所有的代码都是可以直接运行的,这下算是又掌握了一个东西

2.方法

(1)toString():转换成字符串,返回其内容

(2)getClass():返回运行时的类

(3)equal(),和==的区别与联系:对于非字符串,二者无区别;equal()强调的是内容,而==比较的是首地址

3.总结:

   1)开始了前端知识的学习。

   2)参加越野赛的补测。

   3)参加历史校外实践活动,参观了平原博物馆。并且还去进行问卷调查

   4)这一周中自己在学习Java的时间比较少,一直在忙班级和校外实践的东西,放慢了进度,所以之后要更加努力,不忘初心,更加向前。

   5)自己的不足在于学者忘着,没能做到反复去学习,去巩固,之后会改进,做得更好。

 

posted @ 2018-11-23 14:45  谢兴博  阅读(74)  评论(0编辑  收藏  举报