Design a student class student and test

Source: Internet
Author: User
3, design a student class student, and carry on the test
Requirements are as follows:
1 Student class contains name, score two attributes
2 Define two methods for each property, one for setting the value, and the other for getting the value.
3 The Student class defines a parameterless construction method and a construction method that receives two parameters, and two parameters are assigned to the name and grade attribute, respectively.
4 Create two student objects in the test class, one using the parameterless construction method, and then invoking the method to assign the name and the result, a constructor method with a parameter to assign the name and result in the constructor
Class Student {
	private String name;
	private double grade;
	Public Student () {
	} public
	Student (String name, double grade) {
		this.name = name;
		This.grade = grade;
	}
	Public String GetName () {return
		name;
	}
	public void SetName (String name) {
		this.name = name;
	}
	Public double Getgrade () {return
		grade;
	}
	public void Setgrade (double grade) {
		this.grade = grade;
	}
}
public class Test01 {public
	static void Main (string[] args) {
		Student stu1 = new Student ();
		Stu1.setname ("Zhangsan");
		Stu1.setgrade ();
		Student STU2 = new Student ("Lisi";
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.