Java Learning Path (iii)--thinking in Java

Source: Internet
Author: User

In the world of Java, "All Things are objects". This embodies the concept of Java design.

Since everything is object, any object reference must be initialized during the creation process. This is like the relationship between TV and remote control. The remote control is your TV reference, creating an instance of the TV, this example is the remote control. It can control all the behavior of TV. This includes part of the instantiation.

Any object instantiation must be initialized during the creation process. So-called initialization, for class objects (which we take for granted), there are constructors in class, similar to C + + constructors. For initialization of basic data types (i.e., fields), such as int,short,long,double, it is best to initialize them directly during the creation process, although these fields may be initialized by default during the creation process, but since they are all objects, we'd better initialize them to take control of the whole world.

In the process of initialization, the order of initialization is especially important. Although Java has been improved a little bit more than C + +, for example: int i = f ();

int F () {return 11;}? The function f () is required to be declared in C + +, but it is not required in Java.

And the following code:

1  Public classtest{2 3               inti = g (j);//Illegal forward reference4 5               intj =f ();6 7               intGinti) {8 9                      return2 *i;?Ten  One               }? A  -               inti =f (); -  the               intF () {return11;} -  -}?

It's not working in Java. Because you initialize I without initializing J.

Java Learning Path (iii)--thinking in Java

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.