当前位置: 代码迷 >> Java相关 >> 错误的问题
  详细解决方案

错误的问题

热度:101   发布时间:2006-10-18 11:57:48.0
错误的问题

public class MyStudent{
private String stuName;
private String stuAge;
private String stuSex;
public static void setVar(String name,int age,String sex){
stuName=name;
stuAge=age;
stuSex=sex;
}
public static void setSex(String sex){
String stuSex=sex;
}
public static String getName(){
return stuName;
}
public static int getAge(){
return stuAge;
}
public static String getSex(){
return stuSex;
}
public static void main(String[] args){
setVar("maomao",22,"nan");
setSex("nv");
String myMame=getName();
System.out.println(myName);
int myAge=getAge();
System.out.println(myAge);
String mySex=getSex();
System.out.println(mySex);
}
}
怎么报这么多错误啊,哪个有时间帮我看看 初学者.

[此贴子已经被作者于2006-10-18 12:02:24编辑过]

搜索更多相关的解决方案: void  age  private  public  return  

----------------解决方案--------------------------------------------------------
建议先去看看基础的东西先
否则我们说你也是看不懂的
----------------解决方案--------------------------------------------------------

我帮你看看,,,看上去挺简单的问题。。。一会回来。。


----------------解决方案--------------------------------------------------------
stuName=name;
stuAge=age;
stuSex=sex;

一眼可以看出的错误public static void main(String[] args) 里 没为类实例化

还有name age sex是哪来的?


----------------解决方案--------------------------------------------------------
public class MyStudent{
private String stuName;
private String stuAge;
private String stuSex;
public static void setVar(String name,int age,String sex){
stuName=name;
stuAge=age;
stuSex=sex;
}
public static void setSex(String sex){
String stuSex=sex;
}
public static String getName(){
return stuName;
}
public static int getAge(){
return stuAge;
}
public static String getSex(){
return stuSex;
}
public static void main(String[] args){
setVar("maomao",22,"nan");
setSex("nv");
String myMame=getName();
System.out.println(myName);
int myAge=getAge();
System.out.println(myAge);
String mySex=getSex();
System.out.println(mySex);
}
}
就可以运行了 ,注意static的用法
----------------解决方案--------------------------------------------------------
public class MyStudent{
private static String stuName;
private static String stuAge;
private static String stuSex;
public s static tatic void setVar(String name,int age,String sex){
stuName=name;
stuAge=age;
stuSex=sex;
}
public static void setSex(String sex){
String stuSex=sex;
}
public static String getName(){
return stuName;
}
public static int getAge(){
return stuAge;
}
public static String getSex(){
return stuSex;
}
public static void main(String[] args){
setVar("maomao",22,"nan");
setSex("nv");
String myMame=getName();
System.out.println(myName);
int myAge=getAge();
System.out.println(myAge);
String mySex=getSex();
System.out.println(mySex);
}
}

----------------解决方案--------------------------------------------------------

我的电脑有点问题总是复制错的东西 这个是正确的了!!!这个程序不难但是看明白了能明白好多东西,我也是初学者!!!
public class MyStudent{
private static String stuName;
private static String stuAge;
private static String stuSex;
public s static tatic void setVar(String name,int age,String sex){
stuName=name;
stuAge=age;
stuSex=sex;
}
public static void setSex(String sex){
String stuSex=sex;
}
public static String getName(){
return stuName;
}
public static int getAge(){
return stuAge;
}
public static String getSex(){
return stuSex;
}
public static void main(String[] args){
setVar("maomao",22,"nan");
setSex("nv");
String myMame=getName();
System.out.println(myName);
int myAge=getAge();
System.out.println(myAge);
String mySex=getSex();
System.out.println(mySex);
}
}


----------------解决方案--------------------------------------------------------
我也是菜鸟类

static是声明静态方法,不要在每个地方都用,非静态不能调用静态方法


----------------解决方案--------------------------------------------------------
建议去看看基础的东西,今天上午本来想给你改,但是你的错误太多了,改的太多就失去原来的意思了!
----------------解决方案--------------------------------------------------------

谢谢.
静态方法不能调用非静态的东西?

[此贴子已经被作者于2006-10-18 18:54:40编辑过]


----------------解决方案--------------------------------------------------------
  相关解决方案