请教高手java出现需要<标识符>
代码:publicclassPeople{doublehight;Stringhead;voidspeak(Strings){System.out.println(s);...
代码:
public class People
{
double hight;
String head;
void speak(String s)
{
System.out.println(s);
}
}
class A //主类
{
People zhubajie;
zhubajie=new People();
zhubajie.hight=1.88;
zhubajie.head="大头";
System.out.println("身高:"+zhubajie.hight);
System.out.println("头:"+zhubajie.head);
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
}
}
错误提示:
C:\1000>javac People.java
People.java:13: 需要 <标识符>
zhubajie=new People();
^
People.java:14: 需要 <标识符>
zhubajie.hight=1.88;
^
People.java:15: 需要 <标识符>
zhubajie.head="大头";
^
People.java:16: 需要 <标识符>
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 非法的类型开始
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ')'
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ';'
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 非法的类型开始
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ';'
System.out.println("身高:"+zhubajie.hight);
^
People.java:17: 需要 <标识符>
System.out.println("头:"+zhubajie.head);
^
People.java:17: 非法的类型开始
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ')'
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ';'
System.out.println("头:"+zhubajie.head);
^
People.java:17: 非法的类型开始
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ';'
System.out.println("头:"+zhubajie.head);
^
People.java:18: 需要 <标识符>
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
^
People.java:18: 非法的类型开始
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
^
People.java:20: 需要为 class、interface 或 enum
}_
^
18 错误 展开
public class People
{
double hight;
String head;
void speak(String s)
{
System.out.println(s);
}
}
class A //主类
{
People zhubajie;
zhubajie=new People();
zhubajie.hight=1.88;
zhubajie.head="大头";
System.out.println("身高:"+zhubajie.hight);
System.out.println("头:"+zhubajie.head);
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
}
}
错误提示:
C:\1000>javac People.java
People.java:13: 需要 <标识符>
zhubajie=new People();
^
People.java:14: 需要 <标识符>
zhubajie.hight=1.88;
^
People.java:15: 需要 <标识符>
zhubajie.head="大头";
^
People.java:16: 需要 <标识符>
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 非法的类型开始
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ')'
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ';'
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 非法的类型开始
System.out.println("身高:"+zhubajie.hight);
^
People.java:16: 需要 ';'
System.out.println("身高:"+zhubajie.hight);
^
People.java:17: 需要 <标识符>
System.out.println("头:"+zhubajie.head);
^
People.java:17: 非法的类型开始
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ')'
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ';'
System.out.println("头:"+zhubajie.head);
^
People.java:17: 非法的类型开始
System.out.println("头:"+zhubajie.head);
^
People.java:17: 需要 ';'
System.out.println("头:"+zhubajie.head);
^
People.java:18: 需要 <标识符>
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
^
People.java:18: 非法的类型开始
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
^
People.java:20: 需要为 class、interface 或 enum
}_
^
18 错误 展开
1个回答
展开全部
你class A的主类怎么没主函数啊?也就是main函数啊,你的输出要放在主函数里的。所以应该是这样
class People
{
double hight;
String head;
void speak(String s)
{
System.out.println(s);
}
}
public class A //主类
{
public static void main(String args[]){
People zhubajie;
zhubajie=new People();
zhubajie.hight=1.88;
zhubajie.head="大头";
System.out.println("身高:"+zhubajie.hight);
System.out.println("头:"+zhubajie.head);
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
}
} 注意了,People类是默认访问符的,而A类是public的,因为你的A类是主类,一个源文件中只能有一个public的类,而且必须是主类,这样你编译的时候编译javac A.java就可以实现你的结果了。
class People
{
double hight;
String head;
void speak(String s)
{
System.out.println(s);
}
}
public class A //主类
{
public static void main(String args[]){
People zhubajie;
zhubajie=new People();
zhubajie.hight=1.88;
zhubajie.head="大头";
System.out.println("身高:"+zhubajie.hight);
System.out.println("头:"+zhubajie.head);
zhubajie.speak("师傅,咱们别去西天了,改去月宫吧");
}
} 注意了,People类是默认访问符的,而A类是public的,因为你的A类是主类,一个源文件中只能有一个public的类,而且必须是主类,这样你编译的时候编译javac A.java就可以实现你的结果了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询