Object-oriented basics: object usage and object-oriented basic objects

Source: Internet
Author: User

Object-oriented basics: object usage and object-oriented basic objects

Object usage

Call variables and functions using objects:

Object.Variable object.Function ()

For example, create a Dog class and use an object

// Class file Dogclass Dog {String name; // The first letter must be an int age; String color; void jump () {System. out. println ("jump ");}}
Class Test {public static void main (String args []) {Dog d = new Dog (); d. name = "wangcai"; d. age = 2; d. color = "white"; d. jump (); System. out. println ("name is" + d. name );}}

 

Generate multiple objects:

Dog d1 = new Dog (); Dog d2 = new Dog (); // The two objects are independent.

 

Use of anonymous objects:

You can directly call the method of this object without defining the reference name of the object. For example:

New Dog (). jump ();

Anonymous objects are usually disposable and cannot be found after use ..


Basic questions about Object-Oriented Programming

Right. Both java and c ++ have their own standard libraries, at the same time, their compilation environment also provides a comprehensive class library that encapsulates data structures, algorithms, Human-Computer Interaction interfaces, and other content. In particular, some important data structures and algorithms greatly simplify and reduce programmer programming tasks. Many classes can be used directly, or you can create your own inherited classes based on them. Of course, the work of specific programming is ever-changing. Besides using the content in the class library, writing classes by yourself is inevitable.

What is the object in Java object-oriented programming?

The object is the meaning of the class instance.
Object-oriented

Object-oriented is a new method of programming, or a new model of programming. Its basic idea is to use objects, classes, inheritance, encapsulation, message and other basic concepts for program design.

It constructs a software system based on objective things (objects) in the real world, and tries its best to use human natural thinking methods in system construction, it emphasizes that the problem is directly centered on things in the problem domain (the real world) to understand the problem, and abstract these things as objects in the system based on their essential characteristics, as the basic unit of the system (instead of using other concepts that are far from relevant to things in the real world and have no corresponding relationships ). This allows the system to directly map the problem domain and maintain the original appearance of things in the problem domain and their relationships.

It can be understood at different levels:

From the perspective of world view, we can think that the basic philosophy of object orientation is that the world is composed of various objects with their own motion rules and internal states; the interaction and communication between different objects constitute a complete real world. Therefore, people should understand the world based on the real world, and directly reflect the world through objects and their relationships. In this way, the established system can be in line with the real world.

From the perspective of methodology, we can think that the object-oriented method is the direct application of the object-oriented world view in the development method. It emphasizes that the structure of the system should correspond directly to the structure of the real world, and the system should be constructed around objects in the real world, rather than around functions.

From the perspective of programming, object-oriented programming languages must have language components that describe objects and their relationships. These programming languages can be classified into the following categories: everything in the system is an object; an object is the encapsulation body of an attribute and its operations; an object can be divided into classes by its nature, an instance where an object becomes a class; an instance relationship and an inheritance relationship are static relationships between objects; message transmission is the only form of dynamic connections between objects and the only form of computing; the method is the message sequence.

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.