Java:简单的类的定义
1
2
//---------------------------
3
//我的第二的Java程序
4
//很简单的类的定义
5
//---------------------------
6![]()
7
//---------------------------
8
//学生信息类
9
//BEGIN----------------------
10
class Student
11
{
12
private String Name;
13
private int Age;
14
private String ClassID;
15
16
//构造函数,初始化数据
17
Student(String Name,int Age,String ClassID)
18
{
19
this.Name=Name;
20
this.Age=Age;
21
this.ClassID=ClassID;
22
}
23
//显示学生信息
24
public void Fun_Print()
25
{
26
System.out.println("姓名:"+this.Name+"\t年龄:"+this.Age+"\t班级:"+this.ClassID);
27
}
28
}
29
//END------------------------
30![]()
31
//---------------------------
32
//主函数类
33
//BEGIN----------------------
34
public class SecondJava
35
{
36
public static void main (String[] args)
37
{
38
Student Stu1=new Student("张三",18,"Cla001");
39
Student Stu2=new Student("李四",19,"Cla002");
40
Stu1.Fun_Print();
41
Stu2.Fun_Print();
42
}
43
}
44
//END-----------------------
45![]()
2
//---------------------------3
//我的第二的Java程序4
//很简单的类的定义5
//---------------------------6

7
//---------------------------8
//学生信息类9
//BEGIN----------------------10
class Student11
{12
private String Name;13
private int Age;14
private String ClassID;15
16
//构造函数,初始化数据17
Student(String Name,int Age,String ClassID)18
{19
this.Name=Name;20
this.Age=Age;21
this.ClassID=ClassID;22
}23
//显示学生信息24
public void Fun_Print()25
{26
System.out.println("姓名:"+this.Name+"\t年龄:"+this.Age+"\t班级:"+this.ClassID);27
}28
}29
//END------------------------30

31
//---------------------------32
//主函数类33
//BEGIN----------------------34
public class SecondJava35
{36
public static void main (String[] args)37
{38
Student Stu1=new Student("张三",18,"Cla001");39
Student Stu2=new Student("李四",19,"Cla002");40
Stu1.Fun_Print();41
Stu2.Fun_Print();42
}43
}44
//END-----------------------45



浙公网安备 33010602011771号