Z
Z
zekohina2017-01-02 13:47:53
Java
zekohina, 2017-01-02 13:47:53

How to understand the creation of a child instance of the parent's type?

Found in one example such code.

Parent obj = new Child();
    obj.method();

How is it to be perceived? Where will the methods and properties come from?
Please provide a link where you can read more about it.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
al_gon, 2017-01-02
@zekohina

https://docs.oracle.com/javase/tutorial/java/IandI...
https://www.tutorialspoint.com/java/java_inheritan...
www.java2s.com/Tutorial/Java/0100__Class-Definitio. ..

G
gleendo, 2017-01-02
@evgeniy8705

Methods and properties will either be inherited from the parent or stored in the child class.
In this case, method() can be in both Child and Parent

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question