Object-oriented common face questions in Java

Source: Internet
Author: User
The difference between a member variable and a local variable
1. Different positions in the class:
Member variables: Defined outside the method in the class.
Local variables: On a method declaration or in a method definition.
2. Different locations in memory:
Member variable: heap memory.
Local variables: Stack memory.
3. Different life cycle:
Member variables: Loaded as the class is loaded, and disappears as the class disappears.
Local variables: As the method call exists, disappears as the method call finishes.
4, the initialization value is different:
Member variable: initialized by default by the system. For member variables, you can not give the initialization value, which is given by the system, and then the initialization is displayed.
Local variables: Local variables must be initialized before they are used, otherwise they cannot be used.
There is a student class student, there are some attributes, in the test class to create a student class object, through the process?
Student s=new Student ();
1, through the test class inside main main program to load, load Student class (Student.class);
2, Student s first in the stack memory to open up the stack memory space, create a student object, the heap memory needs to request heap memory space;
3, through the non-parametric construction method to the Student class object default initialization;
4, by assigning values to the member variables, the object is displayed to initialize;
5, the display initialization is complete, after the whole object is created, the object is allocated the memory space address value;
6, find the corresponding object by the address value.

Object-oriented common face questions 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.