static method Java Inheritance

Source: Internet
Author: User
Can inherit, example: Class a{public static void A () {  System.out.println ("a");}} Class B extends A{}public class Test {public   static void Main (string[] args) {         B.A ();//output A, proving that A static method can be inherited   }} cannot be Overwrite, example: class a{public static void A () {  System.out.println ("a");}} Class B extends a{public static void A () {  System.out.println ("B");}} public class Test {public   static void Main (string[] args) {    A A = new B ();    A.A ();//The output is a   }}java is not recommended to call the static method with the object, which can confuse people, please note.

  

You can override a static method, but the overridden static method does not support polymorphism.
The essence is because the static method only looks for the memory of the explicitly declared class at run time, which means it cannot be polymorphic. The operation of the virtual machine is like this, is the grammar provisions, there is no good explanation, as to what the public is not public is nonsense, said did not say the same

static method Java Inheritance

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.