内容发布更新时间 : 2025/6/26 22:07:58星期一 下面是文章的全部内容请认真阅读。
}
}
}
return false; //如果不是,则直接返回false
Persona per=(Persona)obj;//将传进来的对象向下转型
if(per.name.equals(this.name)&&per.age==this.age){ }
return true; return false; }else{
public String toString(){ }
return \姓名:\+this.name+\年龄:\+this.age;
public class ObjectDemo1 { }
public static void main(String[] args) { }
Persona per1=new Persona(\小明\,20); Persona per2=new Persona(\小强\,22); Persona per3=new Persona(\小强\,22);
System.out.println(per1.equals(per2)?\是同一个人!\:\不是同一个人!System.out.println(per2.equals(per3)?\是同一个人!\:\不是同一个人!System.out.println(per1.equals(\)?\是同一个人!\:\不是同一个
\); \); 人!\);
显示结果:
不是同一个人! 是同一个人! 不是同一个人!
一、使用面向对象的概念表示出下面的生活场景:
小明去超市买东西,所有买到的东西都放在了购物车之中,最后到收银台一起结账。
class Customer{
private String name;
public Customer(String name){ this.name=name;
System.out.println(\顾客姓名:\+name); } }
class Goods{
private String gname; private double price;
}
private static float countPrice; private static int countGoods;
public Goods(String gname,double price ){ }
public String getGname(){ }
public double getPrice(){ }
public void getGood(){ }
public String getCount(){ }
return \商品总数:\+countGoods+\商品总额:\+countPrice+\元\; System.out.println(\商品名称:\+gname+\商品价格\+price+\元\); return price; return gname; this.gname=gname; this.price=price; countPrice+=price; countGoods++;
class Cart{ }
public class Buy {
public static void main(String[] args) {
Customer cus=new Customer(\小明\); private Goo