黑马程序员技术交流社区
标题:
*********一直提示要标识符*********
[打印本页]
作者:
顾亦飞
时间:
2012-6-21 17:12
标题:
*********一直提示要标识符*********
本帖最后由 顾亦飞 于 2012-6-22 10:46 编辑
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!);
}
复制代码
作者:
王晓新
时间:
2012-6-21 18:43
class Dog
{
String name;
String says;
void setDog(String n,String s)
{
this.name = n;
this.says = s;
System.out.println("name="+n+" +says="+s);
}
}
public class DogTest
{
public static void main(String[] args)//main方法的大括号掉了。。。
{
Dog d1 = new Dog();
d1.setDog("spot","Ruff!");//这里你给的参数是字符串,要加“”
Dog d2 = new Dog();
d2.setDog("scruffy","Wurf!");//这里一样要加""
}
}
复制代码
作者:
金龙
时间:
2012-6-21 21:31
楼上正解,你定义的两个属性都是String(字符串)类型的,传参数的时候肯定是字符串类型啊,而字符串需要用双引号去标识,以后要记得小心啊
作者:
王涛
时间:
2012-6-21 22:04
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!");
}
}下面这个大括号丢了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2