java--Object-oriented

Source: Internet
Author: User
Tags modifiers

What is an object?

Everything objects, objects due to concern and produce!!!

Class and object relationships?

1, the class is an abstract object, the object is an instance of the Class!

2. A class is a set of objects that have the same properties and behaviors

3, in the software system, you can use classes to simulate real-life entities

  Object-oriented thinking 1. Object: An object can be any person, thing, or entity that appears in the problem domain, simply saying "something".  2. After the objects in the problem domain have been found, we will write a class to describe the properties and behavior of each object. A property is what value data the object has, the behavior is what the object can do, or what we want these objects to do;  write Java class Java classes with the keyword class declaration example: public class student{} The above example is a name stud ENT Java class   Add member variables (attributes) to a Java class, the composition of member variables: a member variable in a class consists of the following parts: 1, access modifiers.  It can be public, private, or protected, and if the access modifier is omitted, the default access modifier is used.  2, data type. 3. Name of the member variable. The member variable name must be a valid identifier followed by a semicolon end.   Method (behavior) The behavior of an object becomes a method in the related class. A method in a class is typically made up of the following: the access modifier returns the type method name, must be a valid identifier parameter list, and the definition of the method in parentheses appears   method definition: Method and Signature: access modifier. Possible values for the access modifier include public, private, protected, or the default access modifier   optional modifiers. The next part of the method signature is an optional modifier, including static, final, abstract, native, and synchronized.  The native method is used to write a Java access map to a method written in a different programming language. The return type. The method signature must include the type of the return value.  If the method does not need to return a value, void is used. The method name. The method name must appear after the return value.  See the name of the idea!! Formal parameter list.  The method name must be followed by a form parameter list enclosed in parentheses. Throws a list of exceptions.    The method can throw an exception to the caller of the method.  Parameters within a method: When we define a method's signature, include a list of formal parameters (Parameter), which is used to declare the type of data passed to the method. The data passed to the formal parameter when we call the method is called the actual parameter (arguement). When a method is called, the actual argument must be passed to each formal parameter in the formal argument list. Overloading of the   method: When a class has twoTo multiple methods with the same name but with different parameter lists, this is the method overload. Overloading a method, as long as the form parameter list of a method is very different to the compiler, allows the compiler to distinguish which method we want to invoke.        Constructor: A constructor is a special method that is called to execute when a class creates an instance. The purpose of the constructor is to initialize an instance of the class so that it becomes a valid state.  As long as an object is created, the object must be correctly initialized to a valid state by the data member in the constructor.  The name of the constructor must be the same as the class name.  If a constructor is not declared when a class is defined, the Java compiler will specify a default constructor constructor for the class that cannot have any return type.  We can create multiple constructors for a class as long as the following conditions are true.  – The constructor has a different number of arguments;  if the constructor has the same number of arguments, the type of the parameter is different, and the class is created with a class that can produce the object.  Why do you want to produce objects?  Because the class is just a template, the object is the real concrete existence how to produce the object?  Use the new method to produce the object.    Example: We have written a Java class named: Student, which we use to produce an object Student stu = new Student (); Access to the properties and methods used by the. (dot operator) to access the:        example: with the object name. (point) attribute or method: Above we new A object named: Stu,  Now let's access the Stu object and properties and methods Student stu = new Student (); stu.name; (attribute) stu.age; (attribute) stu.write (); Method

  

java--Object-oriented

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.