Java Fundamentals 3

Source: Internet
Author: User

1. What kinds of variables are divided by scope? What do I need to be aware of when using local variables?

Classification by scope: Local variables, member variables, static variables;

Local variables: 1, local variables must be initialized before they are used. 2, you need to be aware of the scope. 3, modifiers for local variables can only be default and final.

2. What is the difference between a static variable and a member variable? How should I call it?

1, static variables are independent of variables outside the object are many objects shared variables, when an object changes it, will affect all objects;

Member variables are part of an object, are variables contained within an object, each object has independent member variables, different objects, and the values of member variables may be different, also known as attributes;

2, the member variables are stored in the heap space, and the static variables are stored in the data section;

3, the member variables are generated with the object, destroyed with the object destruction, static variables in class loading is generated, the timing of the object, once the generation of resident memory;

4, member variables can only be called through the form of the object. Static variables may be called by the form and object of the class name.

3. Garbage Collection GC What kind of objects are recycled?

The object that is not pointed to by any variable is recycled, and the object is not in use;

4. What is a package? What is the purpose of the package? How do I import a class from another package? What kind of class does not need to be imported?

The package is also a folder, which is declared in which package by Pakeage;

    1. Organization-related classes 2. Information hiding;

This class can be imported through the full path of the import class;

The classes in this package, and the classes in java.lang*, do not need to be imported and can be used directly;

5. can a static method invoke a member method or property directly? Why?

No, because static methods are loaded before the object, and the member methods and properties are only generated after the object is produced.

Java Fundamentals 3

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.