a.首先书上的代码就是完整的一个类,但不是main类,这个类可以在其他类里面调用
b.你写的类其实就是加了main方法,但是你没有在main方法里调用你的下面的方法,
public class Student
{
static float height,weight;//成员变量定义
static String name,sex,no;//成员变量定义
public static void main(String[]args)
{
setStudent("李史","男","1号");
}
static void setStudent(String n, String s, String o){//方法定义
name=n;sex=s;no=o;
System.out.println("姓名:"+name + "\n性别:"+sex + "\n学号:"+no);
}
static void setWH(float w,float h){//方法定义
weight = w; height = h;
}
}
3.要是用课本上的,输出的结果完全一样