Java objects and classes. And method overload ., Java overload

Source: Internet
Author: User

Java objects and classes. And method overload ., Java overload

Object:

Everything is an object.
The object consists of attributes (nouns and adjectives) and actions (verbs ).
Objects are related to each other: Derivation, association, and dependency.

Class:

An abstraction of many objects in the same category.
Class, or a template used to generate an object. An object is a concrete manifestation of the class.

Object-oriented features: encapsulation, inheritance, and polymorphism.

Class name {
Definition of access modifier member variables;
Definition of access modifier member functions (methods;
}

Access modifier: by default, it is not written, private, or public.
1. private, private. It can only be accessed by code in the current class name. Out of this class {}, Access failed.
2. public and public. Can be accessed by the current class name. It can also be accessed by objects in other locations.
3. No write by default, which can be accessed in the current class name. Other classes in the current package can also be accessed. If the current package exists, the access fails.

Get and set methods

1. get member variable name () method: used to obtain member variables when the member variables are private.

1. set member variable name () method: when the member variable is private, it is used to directly change the member variable.

Class instantiation: use classes to generate objects.
Class name variable name = new Class Name ();

Class name variable name = new constructor;

Constructor:
1. The class name must be the same.

2. There cannot be a return type.

3. Automatic execution. The new time of the object is automatically executed.

4. It is generally public.

5. initialize the member variable before executing the member function.

6. If this parameter is left blank, it is generally created by default by the system.

Public class gou {// member variable private String mingZi = "rhubarb"; private String zhuRen; // member function (method) public String getMingZi () {return mingZi ;} public void setMingZi (String mingZi) {if (mingZi! = ZhuRen) {this. mingZi = mingZi;} public void jiaoHuan () {System. out. println (mingZi + ": Wang! Wang! Wang! ");}}
Public class home {public static void main (String [] args) {gou a = new gou (); a. setMingZi ("yellow"); // use the set method to change the name. System. out. println ("the name of the puppy is:" + a. getMingZi (); // get the name using the get method. A. jiaoHuan ();

Last display

 

Method overloading:
Function names are the same and parameters are different (quantity and type ). These two functions form an overload.
The overload is irrelevant to the type number returned by the function. The overload is only related to the function name and parameter.
The overloaded function automatically determines which function to call based on the actual parameters called.
In addition to constructors, normal member functions can also be overloaded.

Related Article

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.