Java object-Oriented-Object and class overview

Source: Internet
Author: User
Tags modifier

The Java language provides basic functionality for defining classes, member variables, methods, and so on.

Classes can be thought of as a custom data type, you can use classes to define variables, and all variables that use classes to define are reference variables that reference objects to the class.

Java object-oriented three major features: encapsulation, inheritance, polymorphism.

Encapsulation: Provides three access modifiers for private, protected, and public to implement

Inheritance: Extends keyword lets subclass inherit parent class

Polymorphism : The parent class refers to the subclass object, and the subclass object can be directly assigned to the parent class variable, which is polymorphic and more flexible to use when the inheritance relationship is used to implement it. (Baidu Search: Mulan for the father in the Army cited example)

Classes and objects:

A class is an abstraction of a group of objects that can be understood as a concept;

An object is a concrete entity that exists.

There are three common members in a class: constructors, member variables, methods.

The member of the static modifier indicates that it belongs to the class itself and not to a single instance of the class, so the member variables and methods of static adornments are often referred to as class variables, class methods. A normal method that does not use the static modifier, a member variable belongs to a single instance of the class. The This reference cannot be used in a static decorated method (static direct access, without creating an object), so the static decorated method cannot access an ordinary member that does not use the static adornment, that is, a member of the static adornment cannot access a member that does not have a static adornment. (Most of the data is called static, which is vague and does not explain the real effect of static)

member variables tips: member variables are translated by the English word field, and some early books refer to member variables as attributes. But in fact, in the Java World, properties (translated by property) refer to a set of setter methods and getter methods. For example, a class has an age attribute, which means that the class contains Getage () and Setage () two methods, and some materials, books, and fields are translated into field and domain.

parameter list: once a formal parameter list is specified when the method is defined, the corresponding parameter value must be passed in when the method is called-who invokes the method and who is responsible for assigning the parameter.

shows the meaning of defining a constructor: the constructor can contain parameters, and the constructor contains parameters that are required for the caller: these are the parameters that must be used to create the class. This is more flexible and more prescriptive than directly initializing the values. (for example, a child born with no name, male or female is not sure, but it is certain that the child will cry at birth, when the crying is to create the class must be used) The Java language has the new keyword to call the constructor, thus returning the instance of the class. If a class does not have a constructor, the class typically cannot create an instance (the system can provide a constructor by default). Static modified methods and variables can be invoked either through a class or through an instance.

After the class is defined, the Java class is used roughly by the following functions:

--Defining variables

--Create Object

--calling a method of a class or accessing class variables of a class

Java object-Oriented-Object and class overview

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.