PM code Android "top ranking"

Source: Internet
Author: User
Tags multiple inheritance in java

The android "top ranking"

This is the seventh article in the Android series, and it's the last article on the Java language. After this article, we will formally start the Android learning. However, this article will be a good study, the foundation of Java to play well, then learn Android will be more effective.

Not long ago, the public number of the article has broken through 200,000 words , I am still very happy, a total of more than one article. There are a lot of articles in the planning, I hope I can keep writing down, without your support, I can not have the power code so many words. Next will not always release the Android tutorial, but will be interspersed with the article, but also hope that we continue to support!

Today the main content of this article is as follows, I will continue to use my way for you to tell the original boring programming, today will join Jin Yong Martial Arts top ranking Oh, please be patient read it ┑ ( ̄.  ̄) ┍

1 abstract class

2 interface

3 Packages and access rights

"Abstract class"


Java can create a class specifically to do the parent class , which is called an abstract class . Abstract class is very strange, at first glance, do not understand what the use of it at all. Because it declares only the method, not the implementation ...

Let's start by explaining a few things to note:

1 Abstract Classes and abstract methods must be declared with the abstract keyword

2 Abstract Classes cannot be instantiated directly , that is, the new keyword cannot be used to produce objects directly

3 abstract methods only need to declare, do not need to implement

4 subclasses of an abstract class must override all abstract methods before instantiating, otherwise, this subclass is an abstract class

5 Special Note that the method in the abstract class can be either an abstract method (with the keyword abstract) or a general method (without abstract)

After deep analysis and analogy, I found that the abstract class still has a certain effect. An abstract class is like a " Die (MU) board ", which allows the designer to create and modify new classes according to its format.

Give me a chestnut and you'll understand:

Jin Yong Martial arts world, by generation after generation of the people deeply love, especially like "Tian Long", "Shoot carving", "God carved", "leaning Days" and other outstanding works, we are familiar with. So many works, out of a lot of heroes, and the Chinese like all row a seating, OK, then I will take this opportunity today, to everyone row, say not good, beg pat ...

(1) Top ranking of top experts

Now that I'm going to make the leaderboard, I'm going to start out with a list of criteria, in other words, to get a top-ranked template. So,let ' s do it.

The top master of the template, need to know the hero is which door faction, and then by the various door faction to choose their eyes in the door to the first person (the door to instantiate object ). First of all, we should abstract a template of the Wulin League ranking. May contain information: The name of the hero, the hero from the Jin Yong novels , but also have his kungfu description , like the following:

抽象的武林门派{    大侠的名字;    大侠的出处;    大侠的绝世武功;    对大侠的描述(){    }}

Because this application into the list of the heroes are not sure who is, and do not know which door faction, so "the description of the martial arts" This method is empty, abstract , must wait for the specific applicant to come after, to determine what the content is.

The programming language is written as follows:

abstract class WuLinMenPai{    String DaXiaName;//大侠的名字    String FromWhere;//大侠的出处    String JueShiKongFu;//大侠的绝世武功描述    public abstract String Description();//入榜申请描述}
(2) The heroes who apply to the list enthusiastically

Since I heard that there is a top ranking of the application activities, Jin Yong series of the various door faction eager to give the application of their own door to the template, to raise two chestnuts:

少林派{    少林派申请的大侠(名字,出处,绝世武功)    {        大侠的名字=名字;        大侠的出处=出处;        大侠的绝世武功=绝世武功;    }    对申请人的描述(){        说出“大侠:”+名字+“出处:”+出处+“我的绝世武功有:”+绝世武功;    }}----------------------逍遥派{    逍遥派申请的大侠(名字,出处,绝世武功)    {        大侠的名字=名字;        大侠的出处=出处;        大侠的绝世武功=绝世武功;    }    对申请人的描述(){        说出“大侠:”+名字+“出处:”+出处+“我的绝世武功描述:”+绝世武功;    }

The program version is such a drop, contrast, convenient for you to understand:

少林派class ShaoLin extends WuLinMenPai{    public ShaoLin(String DaXiaName,String from,String JueShiKongFu){        DaXiaName=name;        FromWhere=from;        JueShiKongFu=kongfu;    }    public String Description()    {        return "大侠:"+DaXiaName+",出处:"+FromWhere+"我的绝世神功"+JueShiKongFu;    }   }   ---------------------逍遥派class XiaoYao extends WuLinMenPai{    public XiaoYao(String DaXiaName,String from,String JueShiKongFu){        DaXiaName=name;        FromWhere=from;        JueShiKongFu=kongfu;    }    public String Description()    {        return "大侠:"+DaXiaName+"出处:"+FromWhere+"我的绝世神功描述:"+JueShiKongFu;    }}

Then, each door faction in their own interior gives the judge of the standard, so there are a lot of the heroes enthusiastically put forward the application, after Glen Martial arts expert Scientific Evaluation Committee ,

Top Ranking Finalists list {Shaolin Dharma = Shaolin Faction application of the Warrior ("Dharma", "I come from many places in the Jin Yong series, the basic Shaolin Place, will refer to me", "Nine Yang Magic", "Easy Rib Sutra", "Shaolin 72 stunt"); Carefree faction carefree Old ancestor = Carefree Faction application of the Heroes ("Carefree Lao zu", "from Tianlong Eight", "north of the Underworld", "small without phase", "Lingbo micro-step", "eight", "the Tianshan six Yang palm", etc., but also proficient in medicine, Qi door dun armour, but also long handsome ...    ");    Description of the Dharma (); Propaganda for the second speed of the Old Fathers (); }-----------Program Edition class juedinggaoshouruwei{public static void Main (string[] args) {Shaolin Damo=new shaolin ("        Dharma "," I come from a lot of Jin Yong series of places, basically have Shaolin place, will mention me "," "Nine Yang Martial," "Easy Rib Sutra", "Shaolin 72 stunt", Chinese Buddhist Mountain Huang "); Xiaoyao xiaoyaolaozu=new Xiaoyao ("Carefree Lao zu", "from Tianlong Eight", "North of the Magic", "small without phase", "Lingbo micro-step", "eight Liuhe of the first work", "Tianshan six Yang Palm", etc., but also proficient in medicine, Qi door dun Jia, but also long handsome ...    ");    } System.out.println (Damo.description ()); System.out.println (Xiaoyaolaozu.description ());} ---------------output as follows, and then add some I personally think the top martial arts masters of the Private rankings: (Ranked 1th) Warrior: Dharma Source: I come from many parts of the Jin Yong series, basically have Shaolin place, will mention me my peerless martial arts description: "Nine Yang", " Easy Rib Sutra, "Shaolin 72 stunt", the mountain of Chinese Buddhism Huang (ranked 2nd) Warrior: The source of Carefree Lao zu: from the Dragon Eight part of my peerless martial arts description: "North of the Magic", "small non-phase", "Lingbo micro-step", "eight", "the Tianshan six Yang Palm" and so on, but also proficient in medicine, Qi door dun Jia, Still handsome ... (ranked 3rd) Warrior: Huang Chang Source: Shoot Eagle Hero Biography of my peerless martial Arts description: Martial Arts Supreme Classics "Nine Yin Canon" of the writer (ranked the 4th) Warrior: Lone lonely seek defeat Source: God carved the man and smile proud of my invincible Martial arts description: "Lone solitary Nine Swords", Life with sword to Zhen sublimation, sword no intention, soft sword impermanence, no front, Wooden Sword no lag, no sword no recruit ... (Ranked # 5th)Warrior: The former eunuch Source: Laughing proud of my invincible Martial arts description: "Sunflower Treasure Book" of the original, the east is only practiced for 12 years part of the "Sunflower Treasure Book", has been very strong into that, dare not imagine how powerful he is. 
Interface


Before the introduction of the class, we said that Java is not support multiple inheritance, that is, subclasses in Java only a parent class, analogy martial arts world, a disciple can only have a master .

However, sometimes the reality is complicated, you can only have a master, but you want to learn more martial arts, Java in order to solve this problem, the introduction of the concept of interface.

Interface (interface) is a mechanism for implementing multiple inheritance in Java and is one of the most important aspects of Java design, note:

The 1 interface is similar to an abstract class, but the data members in the interface must be initialized and are constants, for example: An interface defines an age, an int age=25, which must be assigned an initial value to

2 The methods in the interface must all be declared abstract, that is, the interface can not be as abstract as the abstraction of the method, but also the general method

3 because the methods in the interface are all abstract methods, the abstract keyword can be omitted; The member properties in the interface are constants, so the final keyword can be omitted, but children's shoes, do not forget that they have the addition of abstract and final ah ...

The same, the martial arts of chestnuts, to facilitate your understanding:

(1) Jin Yong Series, the most popular warrior--Qiao

Many people very much like Tianlong eight in the Qiao Warrior, with his Li Zilai let everyone understand the concept of interface, I think is the best.

我们知道,乔峰最开始是拜师少林的玄苦大师:师傅 玄苦(少林){    武功1 龙爪手(少林七十二绝技之一);    武功2 降魔掌(少林七十二绝技之一);    门派功夫描述()    {        我们少林的招牌武功是“龙爪手”和“降魔掌”;    }}我们知道,乔峰后来成为了丐帮的帮主:学功夫 汪剑通(丐帮前任帮主){    武功1="降龙十八掌";    武功2="打狗棒法";    门派功夫描述()    {        我们丐帮的招牌武功是“降龙十八掌”和“打狗棒法”;    }}

So, Qiao a military study in fact is a collection of Shaolin and Confraternity essence, but his real master, is his first teacher of the Xuan Bitter master, behind him into the confraternity, and learn military study, but this is not the true meaning of The Apprentice, but another kind of contractual relationship , in the martial arts is allowed such a relationship, In Java it is necessary to use the Interface (interface) :

玄苦大师是父类class XuanKu{    String Kongfu1="龙爪手";//少林七十二绝技之一    String Kongfu2="降魔掌";//少林七十二绝技之一}汪剑通是接口interface WangJianTong{    String Kongfu3="降龙十八掌";    String Kongfu4="打狗棒法";    public void Description();//关于武功的描述}乔峰继承玄苦同时又以另一种契约方式继承汪剑通class QiaoFeng extends XuanKu implements WangJianTong{    public void Description() {        System.out.println(        "乔峰会的功夫是"+Kongfu1+" "+        Kongfu2+" "+Kongfu3+" "+Kongfu4);    }}class Test{    public static void main(String[] args) {        QiaoFeng QiaoFeng=new QiaoFeng();        QiaoFeng.Description();    }}输出结果为:乔峰会的功夫是龙爪手 降魔掌 降龙十八掌 打狗棒法
"Package and access rights"


In front of the basic object-oriented knowledge point of 7788, now talk about a special "package" concept.

A package is a special property of a class, and a package is used to manage a large number of class files, and you can set other people's access rights to class members . The package can be understood as a larger, manageable class (a bit of a mouthful) ...

Or a chestnut, you'll understand:

Into the martial arts world, martial arts is also very big, the woods are big what birds have, there may be two of the name of the door is exactly the same, if this happens in the number one martial art will be held, it is easy to crash, when you see the two name of the door faction, I do not know how you will feel.

For example, the Great Shaolin is divided into several, if they go out all say that they are Shaolin, it is easy to cause confusion, so that the lake and other fellow feel trifling, so, in the north of Shaolin called himself North Shaolin, in the south of Shaolin called himself South Shaolin.

Package in the program is a big role in the use of multiple classes or interfaces, in order to avoid duplicate name of a measure , with the package keyword, declare a packet, with the package to distinguish the same name of the class and interface.

门派 少林(北边){    对外宣传()    {        我是少林派;    }}门派 少林(南边){    对外宣传()    {        我是少林派;    }}在武林大会时,遇到这种情况,就会Duang,闪退。。。如果在前面加了区域(package关键字),就可以将两个门派(类)区分开:区域 北边;门派 少林{    对外宣传()    {        我是少林派;    }}区域 南边;门派 少林{    对外宣传()    {        我是少林派;    }}--------------代码是这样子的:package.north.java;//声明区域class ShaoLin{    public String talk()    {        return "我是少林派";    }}package.south.java;//声明区域class ShaoLin{    public String talk()    {        return "我是少林派";    }}这样子,两个少林派就可以区分了,是不是很神奇??

Precautions

1 The Package keyword will be used to declare the keyword

2 use a different package, will use the keyword import(that is, import meaning)

(The dividing line of sparkly)

Well, through a few articles, have already finished the Java, let us review:

The Android "1-hour learning Java": This article is about basic Java syntax

The Android "martial Arts article: Object-oriented basis": This article outlines the process-oriented and object-oriented, and introduces the important knowledge of object-oriented-Class and Object

The android "martial arts talk about encapsulation, inheritance, polymorphism": This article mainly tells the object-oriented three characteristics--encapsulation, inheritance, polymorphism

"The top ranking of Android" in the Code of the year: This article is about abstract classes, very important interfaces, and the relevant knowledge of the package.

The basic Java knowledge needed to develop Android is almost finished, and there are some bits and pieces of knowledge that are useful, but you can add to this knowledge when you learn to develop Android:

Anonymous objects, construction methods, exception handling, keywords (this, static, Super, Final), string and StringBuffer, etc.

Learning while mending, is a more ideal state, ^^ _ Ah, the mouth is smiling crooked ... It should be Jiangzi's ^_^ ...

The next article can officially start hooking up Android, thank you for your support!

Who's Glen?

I am a 0-year-old product manager from Zhongshan University, commonly known as PM0. Coming out of the campus, sharing the face, products, data, reading notes, connected lakes and rivers, I hope you and I in the product of the road together to grow, mutual encouragement!

From the Media Alliance

Jiglen
Since the media Alliance is a gathering bat and other Internet new practitioners of the organization, currently operating as a group, here are the great God, enthusiastic to create and share their own product dry and mental journey, exchange from media operations and creative experience, there are all product managers, The Internet ER's morning reading class and other community bosses camp found excellent articles.
If you are interested in joining us, you can follow my public number Jiglen, stating that you run the public number or other blog, after the approval, will pull you into the group.

PM code Android "top ranking"

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.