Home > Java > javaTutorial > body text

What does person mean in java

下次还敢
Release: 2024-04-27 00:24:17
Original
580 people have browsed it

Person represents a human abstract concept in Java, implemented through a Java class that defines properties and methods. Usually contains attributes (name, age, gender, occupation) and methods (self-introduction, conversation, work).

What does person mean in java

What does person mean in Java?

In Java, person is an abstract concept, usually used to represent a person with attributes and behaviors. It can be implemented through Java classes that define properties and methods related to people.

Attributes

person class usually has the following attributes:

  • Name: person Name
  • Age:Age of the person
  • Gender:Gender of the person
  • Occupation: Person's occupation

Methods

The person class can also have the following methods:

  • Introduce yourself: Let person introduce itself to its attributes
  • Conversation: Allow person to talk to other person Talk
  • Job: Have person perform tasks related to their career

Achieve

The following is a sample Java code that implements the person class:

<code class="java">public class Person {
    private String name;
    private int age;
    private String gender;
    private String occupation;

    public Person(String name, int age, String gender, String occupation) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.occupation = occupation;
    }

    public void introduce() {
        System.out.println("My name is " + name + ", I am " + age + " years old, I am a " + gender + ", and I am a " + occupation + ".");
    }

    public void talk() {
        System.out.println("Hello, how are you?");
    }

    public void work() {
        System.out.println("I am working on a project.");
    }
}</code>
Copy after login

Usage

person## can be created and used using the following code #Instance of class:

<code class="java">Person john = new Person("John Doe", 30, "male", "software engineer");
john.introduce();
john.talk();
john.work();</code>
Copy after login
This will output:

<code>My name is John Doe, I am 30 years old, I am a male, and I am a software engineer.
Hello, how are you?
I am working on a project.</code>
Copy after login

The above is the detailed content of What does person mean in java. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!