jeudi 26 mars 2015

Advantage of Declaring and Initializing Different Object types?


I am learning how to use java to program, and am just learning about abstract classes and how they are useful. Say I have a class which extends another abstract class, which has 2 methods, one of which is abstract. My other, nonabstract class has 4 methods, two of which are the same as in the abstract class, and also defines the abstract method. When initializing my second object, my course tells me to use: (abstract class) foo = new (nonabstract class)(); My question, is that using this code prevents you from using the methods that have been added in the nonabstract class, and as a result, what is the advantage of using that code over (nonabstract class) foo = new (nonabstract class), which lets you use both the methods in the abstract class and the methods added in the nonabstract class. Thanks for the help in advance.





Aucun commentaire:

Enregistrer un commentaire