Object and object variables do not confuse

Source: Internet
Author: User

Objective

A big difference between Java and C + + is the definition of an object. In C + +, defining an object is directly:

  Class Name Object name (construction parameter);

You can do it.

But Java is not so defined. So how do you define it in Java? What are the implications of such a definition? This is what this article is going to tell you.

Methods for defining object variables in Java

  Class Name Object name = new class name (structural parameter);

The smart reader must have discovered that the problem here- new Returns a pointer , and the assignment number to the left is a class type , is there an implicit conversion?

The answer is no.

The name of the class name Object in Java; An object variable is generated, which is itself a pointer type (pointing to an object), which differs from C + +. an object is generated directly in C + +.

It can be thought that the " object " in Java is actually a pointer to an object in C + +, which should be referred to as an object variable .

Object and object variables do not confuse

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.