Java Fundamentals-Super and this parsing

Source: Internet
Author: User

1. Superkeyword denotes the meaning of the super (parent) class. The This variable represents the object itself.

2. Super Access the parent quilt class hidden variables or overridden methods. The current class hypothesis is inherited from the superclass when super is called. XX () is the XX () method that calls the base class version number.


The superclass is the recent parent class.

3. Call the super () parent class constructor only to invoke the first line in the subclass constructor

4. Thiscan only be used in non-static methods in a class. This is absolutely not allowed in static methods and static blocks of code, which are explained clearly in the article "javakeywordstatic, Final use summary".

And this is only associated with a particular object, not with a class, different objects of the same class have a different this

Liezi:

Class Person {    protected void print () {       System.out.println ("The Print ()-Class person."),    }} public class De Mosuper extends Person {public    demosuper () {       super ();//Call the constructor method of the parent class. And put the first line. If you do not write, the system itself is actively added    } public    void print () {       System.out.println ("The Print () in class Demosuper.");       Super.print ();//Call the method of the parent class    } public     static void Main (string[] args) {       demosuper ds = new Demosuper ();       Ds.print ();    }}



Java Fundamentals-Super and this parsing

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.