Summary caused by inheritance of static internal classes by static internal classes

Source: Internet
Author: User

1. Inheritance of static classes

 Public     Static     Class  Productinfo {
Public Static Final String p_id = " ID " ;
Public Static Final String product_type = " ID " ;
Public Static Final String p_name = " ID " ;
Public Static Final String price = " ID " ;
Public Static Final String pay_category = " ID " ;
Public Static Final String rating = " ID " ;
Public Static Final String icon_url = " ID " ;
Public Static Final String short_description = " ID " ;
Public Static Final String app_size = " ID " ;
Public Static Final String source_type = " ID " ;
Public Static Final String author_name = " ID " ;
Public Static Final String ratings_count = " ID " ;
Public Static Final String special_flag = " ID " ;

Public String p_id;
Public String product_type;
Public String name;
Public String price;
Public String pay_category;
Public String rating;
Public String icon_url;
Public String short_description;
Public String app_size;
Public String source_type;
Public String author_name;
Public String ratings_count;
Public String special_flag;

}

Public Static Class Productdetailinfo Extends Productinfo {
Public String packagename;
Public String version_code;
Public String comments_count;
Public String download_count;
Public String long_description;
Public String publish_time;
Public String screenshot_1;
Public String screenshot_2;
Public String screenshot_3;
Public String screenshot_4;
Public String screenshot_5;
Public String version_name;
Public String uses_permission;

}

Can this be done?

Before answering this question, let's first think about how to use the static keyword?

First, when you want to make a variable irrelevant to the instance object of its class, no matter how many new objects are generated, the data is only stored in the memory.

For example, a constant, because you may reference this variable in other classes, and you do not want to create a new object, you can only use the static keyword.

Type 2: When you want a method not to be associated with the instance object of its class.

When to use internal classes

When Class A needs to use the Instance Object of class B and class B also uses the variable or method of Class A, Class B needs to be defined as the internal class of Class. If Class B is not allowed to use the variables or methods of Class A, and other external classes frequently use the variables or methods of Class B, you can set Class B to a static internal class of Class.

Analyze the precedingCode:

This static class is a static internal class of the gfanstore class.

1. Why are these two classes defined as static internal classes?

Because the static internal class does not depend on its external class, and no external class object is created in real time, we can still create internal class objects, when we want to create a productinfo Instance Object in other classes, if it is a simple internal class, then we need to first create the Instance Object of the gfanstore class (only in this way can this internal class be loaded into the memory) before creating

The instance object of productinfo. For a simple internal class, we usually only use it inside the external class. For example, in a view, I need to use the adapter, then I can use an internal class to create a sub-class of baseadapter. This adapter is not allowed in other views, so it is appropriate to use the internal class, however, if we need to use this class in other classes, we need to define it as static so that this static internal class can be used as an external class, for example, for the above two static internal classes, I need to create their instance objects in the view. I can directly create new objects, which is very simple.

2. Inheritance of static internal classes

Static internal classes inherit static internal classes, but it looks awkward.

Appendix:

Referencing a netizen'sArticleIs fully written.


Http://lavasoft.blog.51cto.com/62575/179484/

Another article is to indirectly implement multi-class inheritance through internal classes.


Http://jiangzhengjun.javaeye.com/blog/658353

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.