Java方法的重写

艾文妮 艾文妮 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
[size=18px]
public class MissLi0921 {
public static void main(String[] args) {
Date date=new Date();
Student stu=new Student("张三",89);
TV tv=new TV("电视机",8776);
System.out.println(date.toString());
System.out.println(stu.toString());
System.out.println(tv.toString());

}
}
class Student{
String name;
double score;
Student(String name,double score){
this.name=name;
this.score=score;
}
public String toString(){
return "姓名"+name+"分数"+score;
}

}
class TV{
String name;
double price;
TV(String name,double price){
this.name=name;
this.price=price;
}
}


为什么Date和Student类重写了toString方法TV没有重写
[/size]
...全文
评论 4
收藏 已收藏
分享
返回顶部
艾文妮
非技术区 23,404 成员 70,505 内容