定义一个表示学生的类student,包括属性:学号,姓名,性别,年龄;

方法:获得学号,姓名,性别,年龄;修改年龄。并书写java程序创建student类的对象及测试其方法的功能

1、新建一个272.php,如图所示:

2、输入php网页的结构(<?php?>),如图所示:

3、声明PHP与浏览器交互的文件类型和编码,如图所示:

4、使用class关键字,定义一个Student类,代码如图所示:

5、给Student类添加成员变量和成员方法,代码如图所示:

6、给Student类,创建一个对象,代码:$s1=newStudent()。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-25
public class Student { //定义一个学生类
private int StuNum; //学号
private int Name; //姓名
private char Sex; //性别
private int Age; //年龄
public Student(int StuNum, int Name, char Sex, int Age){//构造函数
this.StuNum = StuNum;
this.Name = Name;
this.Sex = Sex;
this.Age = Age;
}
public int getStuNum() { //获得学号
return StuNum;
}
public int getName() { //获得姓名
return Name;
}
public char getSex() { //获得性别
return Sex;
}
public int getAge() { //获得年龄
return Age;
}
public void setAge(int Age) { //修改年龄
this.Age = Age;
}
}本回答被提问者采纳
相似回答