The staff information of Java object-oriented exercises

Source: Internet
Author: User

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

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.