Android Development Tutorials (1)

Source: Internet
Author: User

At some point in the Android development process, here is a summary of some

    1. This

      In Java, this refers to the method or member of the current object. In particular, when a shape participates in the current object member with the same name, this refers to the member of the current object, without this being the formal parameter.

public void Setthis (string name, int id) {this.name = name;//this.name refers to the method or member of the current object, and the name without this is the formal parameter this.id = ID;}

2. Super

Usage One: Common usage, super refers to the method or member of the parent class.

public class Demosuper extends person{public void print () {System.out.println ("Demosuper:"); Super.print ();//Call the parent class's printing method}

Usage Two: Call the parent class constructor

Class person{    public static void prt (String s) {         system.out.println (s);    }      //Parent class Constructor One     person () {         prt ("a  person. ");     }      //Parent class constructor two     person (String  name) {        prt ("A person name is:" +name);     }}public class Chinese extends Person{     Chinese () {        super ();//Call parent class constructor          prt ("A chinese."); (1)     }     chinese (string name) {         super (name);//Call the parent class with the same formal parameter as the constructor two      &nbsP;  prt ("His name is:" +name);     }    chinese ( String name,int age) {        this (name);//Call the constructor that currently has the same formal parameter         prt ("His age is:" +age);     }     public static void main (String[] args) {     Chinese cn=new chinese ();     cn=new chinese ("Kevin");     cn=new chinese ("Kevin",     }}

Summary : "This refers to the current object, super refers to the parent class". Of course, in the various overloaded constructors of Chinese, this and super are still available in various usages of the general method, such as (1), where you can replace it with "this.prt" (because it inherits that method from the parent class) or "Super.prt" (because it is a method in the parent class and can be accessed by the class), it works correctly. But it seems to be a little superfluous flavor.


Reference documents:

    1. http://blog.163.com/[email protected]/blog/static/1717240672012620111028892/

Android Development Tutorials (1)

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.