Java_构造函数初见

public class TestCourse
{
	public static void main(String args[])
	{
		Course course = new Course("1111", "《程序设计》", "6分");
		course.printCourseInfor();
	}

	/*
	 *========课程信息========
	 *课程号:1111
	 *课程名:《程序设计》
	 *课程学分:6分
	 */
}

class Course
{
	private String cno;
	private String cname;
	private String credit;
	public Course() {}//构造函数
	public Course(String con, String cname, String credit)//构造函数的重载
	{
		this.cno = con;
		this.cname = cname;
		this.credit = credit;
	}
	public void printCourseInfor()
	{
		System.out.println("========课程信息========");
		System.out.println("课程号:" + this.cno);
		System.out.println("课程名:" + this.cname);
		System.out.println("课程学分:" + this.credit);
	}
}

你可能感兴趣的:(Java_构造函数初见)