The use of this and super

Source: Internet
Author: User
Tags goto java keywords

Java keywords:

A, some Java in a specific meaning, and used to do special use of the word is called a keyword, to represent a data type or structure;

b, all the keywords in Java are lowercase;

C, goto and const, although never used, are also reserved as Java keywords;

D, keywords cannot be used as variable names, method names, class names, package names, and parameters;

Currently there are 50 Java keywords:

Final static This super public protected default Privatevolatile synchronized abstract assert Boolean break byte continue Case catch Char Class const Double does extends else float for goto long if implements import native new null instanceof int Interface package return short STRICTFP switch while void throw throws transient try

1. This keyword

Represents a property in a class; You can use this to invoke the constructor method of this class; This represents the current object

(1) Represents a property in a class

[Java]View plain copy public class Person {private String name;   private int age; The parameters that String name and name pass over when instantiated, THIS.name represents the properties of the class public person (String name, int age) {this.name = name;//is       Property Assignment This.age = age for class;       Public String toString () {return "name:" +this.name+ "Age:" +this.age; }   }[Java]View plain copy public class ThisDemo01 {public static void main (string[] args) {person per = new Perso           N ("John", 20);       System.out.println (per); Output results:

[Java] view plain Copy name: John Age: (2) This calls the constructor method of this class

Note: A, the use of this call to the constructor method can only be placed in the first row of the construction method; B, there is at least one constructor in the program that does not use this to invoke the other construction methods, typically using the parameterless construction method as an exit

[Java]  View Plain  copy public class person {       private  string name;       private int age;  //   Define the parameterless construction method        public person () {            system.out.println ("A new person object is instantiated");       }       public person (string name, int age) {            this ()//The parameterless constructor method for person is called             this.name = name;//for the properties of a class            this.age  = age;       }       public string  tostring () {           return  "Name:" +this.name+ "Age:" +this.age;       }  }  

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.