Rewriting the principle explained with polymorphism

1. subclasses access modifiers is greater than or equal to the range of the parent class

class A{

public void m(){}

}

class B extends A{

void m(){}

}

This time access to a range of sub-class is smaller than the parent, let's count it is the anti-push

A a = new B (); // upcast

am (); // a subject is affirmed by the A class can be invoked to process A, m () can be accessed at any position.

am (); // call the method is performed when the specific look subclass, class B will be to call the m (), may itself +

Guess you like

Origin www.cnblogs.com/xuwangqi/p/11085446.html