In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the composition of the Java class to you, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Always like a slogan: life is seven days after seven days. What I want to say is that Java applications are class after class. Java is an object-oriented language, and objects are instantiated from classes. A Java application, whether simple or complex, is composed of several Java classes. Therefore, for beginners, it is necessary to understand the composition of the Java class first.
The Java class is mainly composed of three parts: data members, constructors, and method members.
First, take a look at the following code, which is a simple Java class:
Package com.csst.vo; public class Customer {/ / 1. Data member private String custname; private String pwd; private Integer age; / / 2. Construction method public Customer () {} public Customer (String custname, String pwd) {this.custname = custname; this.pwd = pwd;} public Customer (String custname, String pwd, Integer age) {super (); this.custname = custname; this.pwd = pwd; this.age = age;} / / 3. Method member public String getCustname () {return custname;} public void setCustname (String custname) {this.custname = custname;} public String getPwd () {return pwd;} public void setPwd (String pwd) {this.pwd = pwd;} public Integer getAge () {return age } public void setAge (Integer age) {this.age = age;}}
Composition of the Java class: introduces the three components of the class.
1. Data members:
A data member is a property of a class that declares the properties of an object of that class. Declaring data members often requires declaring the following:
1. Permission modifiers (there are four permission modifiers in Java, which will be described in a later article): the private permission private is used in this example. In most cases, it is recommended that data members use private permissions.
two。 Data types: data members must indicate their data types. The types used in this class are String and Integer. There are two data types in Java, the basic type and the reference type. (it will be described in more detail in a future article).
3. Data member identifier: the name of the data member. Names should follow the Java naming convention. Words with noun nature can be named by numbers, letters, $, _, but the first letter cannot be a number.
4. Initial value: data members may or may not be assigned initial values. If not, there will be default values (depending on the data type).
Second, the construction method:
Constructors are used to create objects, and vice versa, and constructors must be used to create objects. For example, to create a Customer class object, you must call one of the constructors of the Customer class using the new keyword. In this example, there are three construction methods. For example, Customer cust=new Customer ("Gloria", "abc")
3. Method members:
A method member is what an object of this class can do. It is often necessary to declare a few items.
1. Permission access modifier: the same concept as the modifier for data members, the methods in this class use the public permission public.
two。 Return value type: the method member must specify the return value type, or use void if the method does not return a value.
3. Method member identifier: that is, the name of the method. The rule is the same as the data member identifier. It is suggested that the method members should be named with verb words.
About the composition of the Java class is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.