Home> Java> javaTutorial> body text

What does person mean in java

下次还敢
Release: 2024-04-27 00:24:17
Original
524 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,personis 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

personclass usually has the following attributes:

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

Methods

The personclass can also have the following methods:

  • Introduce yourself:Letpersonintroduce itself to its attributes
  • Conversation:Allowpersonto talk to otherpersonTalk
  • Job:Havepersonperform tasks related to their career

Achieve

The following is a sample Java code that implements thepersonclass:

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."); } }
Copy after login

Usage

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

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

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.
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
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!