创建类student和对象
来源:互联网 发布:2017苹果10月份mac 编辑:程序博客网 时间:2024/05/29 08:10
public class Student {
String name; //定义名字
String sex; //定义性别
int age; //定义年龄
public Student(){}; //定义物产构造方法
public Student(String x,String y,int z) //定义有参构造方法,参数为String x,String y,int z
{
name=x;
sex=y;
age=z;
}
void getInfo(String x,String y,int z) //定义方法 getInfo()
{
name=x;
sex=y;
age=z;
}
void showInfo() //定义方法showInfo()
{
System.out.println(“姓名:”+name);
System.out.println(“性别:”+sex);
System.out.println(“年龄:”+age);
}
public static void main(String[] args) { // TODO Auto-generated method stub Student stu1; //定义属于student的对象stu1 stu1=new Student(); //实例化对象stu1 System.out.println("输出第一个人的信息"); stu1.getInfo("叶夜","男",18);//调用方法getInfo(),获取stu1的学生信息 stu1.showInfo(); //调用方法showInfo(),输出stu1的学生信息 System.out.println("输出第二个人的信息"); Student Stu2=new Student("江枫","男",20);//调用方法getInfo(),获取stu2的学生信息 Stu2.showInfo(); //调用方法showInfo(),输出stu2的学生信息 System.out.println("输出第三个人的信息"); Student Stu3=new Student("魍魉","女",16);//调用方法getInfo(),获取stu3的学生信息 Stu3.showInfo(); //调用方法showInfo(),输出stu3的学生信息 System.out.println("输出第四个人的信息"); Student Stu4=new Student("季梅","女",17);//调用方法getInfo(),获取stu4的学生信息 Stu4.showInfo(); //调用方法showInfo(),输出stu4的学生信息 }
}
输出结果如下:
阅读全文
0 0
- 创建类Student和对象
- 创建类Student和对象
- 创建类Student和对象
- 创建类Student和对象
- 创建类Student和对象
- 创建类Student和对象
- 创建类student和对象
- 创建Student类和对象
- 创建类Student和对象
- 类和对象---创建类student和对象
- 创建一个类Student
- 实现类Student的创建
- 创建类Student,在创建该类的对象,并实例化!
- 创建继承类Perint的类Student
- 创建继承类Person的类Student
- 创建继承类Person的类Student
- 创建子类student继承父类person
- 2016-AspNet-MVC教学-6-简单类Student的初次完整创建和使用
- python入门弱智题目
- 分布式事务XA
- 推箱子
- 路由切换及播放
- windows内存结构(1)
- 创建类student和对象
- 分享一个MAC下绕开百度网盘限速下载的方法,三步操作永久生效
- 类和对象
- DEX 文件格式图解
- Banner轮播图的使用
- SSM 封装base(一) 公用增删查改
- angularJs作用域
- stm32修改系统时钟
- C# 去除字符串首尾字符或字符串