Learning Notes--java Classes and objects

Source: Internet
Author: User

Today we learned about Java classes and objects, and because the idea of Java object-oriented programming is almost the same as C + +, you need to focus more on some of the differences in Java.

1. Class

1.1 In the class of this piece, in addition to the basic member variables, member methods, constructors, and so on, need to master the difference between the three permissions modifiers, and will be reasonable to use (private restricted permissions in this class, protected limited permissions only within the package).

1.2 Static constants, variables, methods: static adornments. We can use the "class name. Static class member" to invoke, such as:

 Public class statictest{    staticdouble pi=3.1415;     Static int ID;      Public void Test () {        System.out.println (STATICTEST.PI);        System.out.println (statictest.id);    }}

It is also important to note that the This keyword cannot be used in static methods, and non-static methods cannot be called in static methods. However, you can call a static method in a non-static method.

Tip: When you want to perform initialization actions on a class, you can use static to define a static zone. Such as:

  public class example{     static{            //some     }  }

1.3 Objects

In Java, everything can be considered an object, but a real action identifier is essentially a reference.

The reference to the object is simple, such as: Book Book;

Associate the reference with an object, such as:

   Book Book=new book ();

In Java, the reference essentially holds the memory address of the object, is stored in the stack, and the object is stored in the heap. So the reference is not the object of storage, but generally we ignore the difference.

Also note: Comparison of objects, the difference between = = and the Equals method. The use of the Finalize () method for destroying objects.

  

Learning Notes--java Classes and objects

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.