Read about parent reference to child object in java, The latest news, videos, and discussion topics about parent reference to child object in java from alibabacloud.com
Java study note 12 --- parent class Object Reference pointing to Child class object, learning Note 12 ---
What happens when the object reference of the parent class does not point to the object of the parent class, but to the object of the subclass?
Learn more about parent class references pointing to child classes, and learn more about references pointing
The parent class application points to a subclass object and refers:
The parent class Animal, subclass Cat, Dog. Here, Animal can be an
Public class Animal {Public static void Main (string[] args) {Animal Animal = new Cat ();Animal.voice ();Drinkwater (animal); Call a static method, passing in a subclass object referenced by the parent class }String str;Public void Voice ()
Java Tour (vi)--single case design pattern, inheritance extends, aggregation relationship, child parent class variable relationship, Super, overlay
Java also more and more deep, everyone refueling it! Let's take a step
I. Single-CASE
ExtractJava polymorphism, how to understand parent class references to child class objectsTo understand polymorphism, you first need to know what is "upward transformation".I defined a subclass cat, which inherits the animal class, and the latter is
Java polymorphism, how to understand parent class references to child class objectsTo understand polymorphism, you first need to know what is "upward transformation".I defined a subclass cat, which inherits the animal class, and the latter is the
Member variables:First look at this piece of code:The parent class. Class Fu{int num = 3;} Class Zi extends Fu{int num = 4;void Show () {System.out.println ("num =" +this.num);}} Class Extendsdemo {public static void main (string[] args) {Zi z = new
One.Talk about the completion variables and start talking about the characteristics of the member functions in the child parent class. (also review the differences between the different functions, and why is there such a difference?) )Subclasses
When a parent class reference is directed to a child class object1, the Kawai class overrides a method, the parent class references a new method that calls the subclass to redefine2. The Kawai class does not overwrite a method, the parent class
After the child parent class appears, the class member features:Make a clear list of members in a class:1. Variables2. Functions3. ConstructorsFirst, look at 1. Variables:If a non-private member variable with the same name appears in the child class,
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.