当前位置: 代码迷 >> Java相关 >> 帮忙看看这个程序有啥有关问题
  详细解决方案

帮忙看看这个程序有啥有关问题

热度:4797   发布时间:2013-02-25 21:49:18.0
帮忙看看这个程序有啥问题!
class Person
{
  String name;
  String city;
  int age;
  public Person(String name,String city,int age)
  {
  this.name=name;
this.age=age;
this.city=city;
  }
  public String talk()
  {
  return "我是: "+this.name+",今年: "+this.age+"岁,来自: "+this.city;
  }
  }
  public class P174
  {
  public static void main(String[]args)
{
Person p1=new Person("张三",25,"中国");
Person p2=new Person("李四",30,"中国");
Person p3=new Person("王五",25,"中国");
System.out.println(p1.talk());
System.out.println(p2.talk());
System.out.println(p3.talk());
}
  }
编译时提示说:cannot find symbol!

------解决方案--------------------------------------------------------
//Person p1=new Person("张三",25,"中国");
//Person p2=new Person("李四",30,"中国");
//Person p3=new Person("王五",25,"中国");
这三句修改成这样就行了
Person p1= new Person("张三","中国",25);
Person p2= new Person("李四","中国",30);
Person p3= new Person("王五","中国",25);
------解决方案--------------------------------------------------------
探讨
class Person
{
String name;
String city;
int age;
public Person(String name,String city,int age)
{
this.name=name;
this.age=age;
this.city=city;
}
public String talk()
{
……

------解决方案--------------------------------------------------------
探讨
//Person p1=new Person("张三",25,"中国");
//Person p2=new Person("李四",30,"中国");
//Person p3=new Person("王五",25,"中国");
这三句修改成这样就行了
Person p1= new Person("张三","中国",25);
Person p2= new Person("李四","中国",……

------解决方案--------------------------------------------------------
传值的参数类型要匹配呀!
------解决方案--------------------------------------------------------
我记得Java中参数的值不匹配编译都不会过的吧...
  相关解决方案