Deep understanding of the Super keyword __java in Java

Source: Internet
Author: User

/*

* Write a little bit first, and then specifically have to take the Java programming ideas back to reference

*/

The network to check the Super keyword a lot of ideas are speaking, the Super keyword is a reference to an object of the parent class that represents a parent class object, but the following code test shows that if the parent class is an abstract class, the Superclass keyword can still be used to invoke the non private property or method of the parent class. We all know that abstract classes cannot be instantiated, so this makes me start thinking about what the Super keyword really means (never a parent object).

/*
* Test the Super keyword small problem
*/
Package august26;

public class Test2 {

public static void Main (string[] args) {
TODO auto-generated Method Stub
Son s = new Son ();
S.showinfo ();
}

}
Abstract class Father
{
protected void Showinfo ()
{
System.out.println ("xx");
}
}
Class Son extends Father
{
public void Showinfo ()
{
Super.showinfo ();
System.out.println ("yy");
}

}

Strictly speaking, the This keyword is a reference to a subclass object, and the Super keyword is just a keyword, which is more like an identifier to a parent class.

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.