Write Java applications as required.
(1) Create a class called people :
Properties: Name, age, gender, height
Behavior: Speaking, calculating addition, renaming
Write a construction method that can assign values to all attributes;
(2) Create the main class:
Create an object: named "Zhang San", gender "male", age of five years old, height 1.80;
Let the object invoke the member method:
Say "Hello!" ”
Calculate The value of a 23+45
Change the name to "John Doe"
private string Name;private int age;private string sex;private double height;public string getName () {return name;} public void SetName (String name) {this.name = name;} public int getage () {return age;} public void Setage (int.) {this.age = age;} Public String Getsex () {return sex;} public void Setsex (string string) {This.sex = string;} Public double getheight () {return height;} public void SetHeight (double height) {this.height = height;} void Speak () {System.out.println ("blah blah blah"); void addition (int a,int b) {System.out.println (A + "+" +b+ "=" + (a+b));} void ChangeName () {System.out.print (name+ "renamed"); Name= "John Doe"; System.out.print (name);} public static void Main (string[] args) {people p1=new people ();p 1.setName ("Zhang San");p 1.setSex ("male");p 1.setAge (23); P1.setheight (175); SYSTEM.OUT.PRINTLN ("Basic info" + " +" Name: "+p1.getname () +" Gender: "+p1.getsex () +" Age: "+p1.getage () +" Height: "+p1.getheight ()) ;p 1.speak ();p 1.addition (23°c);p 1.changeName ();
Run results
The staff information of Java object-oriented exercises