java入门3.24(1)

今日所学:

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;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值