A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 顾亦飞 初级黑马   /  2012-6-21 17:12  /  2310 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 顾亦飞 于 2012-6-22 10:46 编辑
  1. class Dog                                 //编译一直提示要标识符,不怎么回事。
  2. {
  3.           String name;
  4.           String says;
  5.           void setDog(String n,String s)
  6.          {
  7.                 this.name = n;
  8.                 this.says = s;
  9.                 System.out.println("name="+name+" +says="+says);
  10.          }
  11.         
  12. }
  13. public class DogTest
  14. {
  15.                public static void main(String[] args)
  16.                Dog d1 = new Dog();
  17.               d1.setDog(spot,Ruff!);

  18.               Dog d2 = new Dog();
  19.              d2.setDog( scruffy, Wurf!);
  20. }
复制代码

4 个回复

倒序浏览
  1. class Dog                              
  2. {
  3.           String name;
  4.           String says;
  5.           void setDog(String n,String s)
  6.          {
  7.                 this.name = n;
  8.                 this.says = s;
  9.                 System.out.println("name="+n+" +says="+s);
  10.          }     
  11. }
  12. public class DogTest
  13. {
  14.           public static void main(String[] args)//main方法的大括号掉了。。。
  15.                  {
  16.                                   Dog d1 = new Dog();
  17.                                   d1.setDog("spot","Ruff!");//这里你给的参数是字符串,要加“”
  18.                                   Dog d2 = new Dog();
  19.                                   d2.setDog("scruffy","Wurf!");//这里一样要加""
  20.                  }
  21. }
复制代码
回复 使用道具 举报
楼上正解,你定义的两个属性都是String(字符串)类型的,传参数的时候肯定是字符串类型啊,而字符串需要用双引号去标识,以后要记得小心啊
回复 使用道具 举报
class Dog                                 //编译一直提示要标识符,不怎么回事。
{
          String name;
          String says;
          void setDog(String n,String s)
         {
                this.name = n;
                this.says = s;
                System.out.println("name="+name+" +says="+says);
         }
        
}
public class DogTest
{
               public static void main(String[] args)
               Dog d1 = new Dog();
              d1.setDog("spot","Ruff!");//这里你传的是字符串,加""

              Dog d2 = new Dog();
             d2.setDog( "scruffy"," Wurf!");
        }
}下面这个大括号丢了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马