Difference between two types of a super class instantiation in Java

107 views Asked by At

I have an abstract super class called Document and two child classes called Magazine and Book. What is the difference between :

Document book = new Book(); and Book book = new Book();

Thank you in advance.

1

There are 1 answers

0
Arthur Eirich On BEST ANSWER

The difference is for example if you have any information about document only in the document class, like, say, price. By doing

Book book = new Book();

you won't be able to get the price of the book, so doing

Document book = new Book();

will give you additional information about your object. Note that price is not the best example. I only wanted to show you how the super-/subclass work.