今日所学:
jdk参考文档中一些子类对父类的继承 几个实例
基本知识: Object是公有的父类
package mmm;
public class Testextends2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Student st=new Student("张三",20,12345);
System.out.println(st.toString());
Student st1=new Student();
Student st2=st1;
System.out.println(st1.equals(st));//继承下来的equals 是判断两个引用对象是不是同一个对象
System.out.println(st1.equals(st2)); //因为st1和st2指向同一个实例 所以返回为true
Student st3=new Student("李四",21,12345);
System.out.println(st3.equals(st));
String str=" abcdefg";
String str1=str.toUpperCase();//小写转换为大写
System.out.println(str1);
System.out.println(str1.charAt(1));//索引 索引是从0开始的
System.out.println("替换后");
System.out.println(str1.replace("A", "C"));//替代
System.out.println(str1.trim());//去掉前面空格
}
}
class Student{//Student 是Object的子类 不用使用extends来声明
int age;
String name;
long id;
public Student(){
}
public Student(String name,int age,long id){
this.name=name;
this.age=age;
this.id=id;
}
public String toString(){ //覆盖
return " "+this.name +" is "+age+"years old";
}
public boolean equals(Student st){//根据序号来判断是否为同一个学生 不应该根据姓名
if(st.id==this.id)
{return true;
}
return false;
}
}