java - Variable Setting to All Subclasses -


is there way insantiate variable encompasses subclasses of class? i've read far must state type variable before setting equal something:

example:

exampleobject1 object = reference object

but if wanted make set variable instance or subclass of object?

yes, can that.

a variable of type t (as long t class/interface/enum/annotation) can hold reference instance of class t, or instance of class extends or implements t.

for example, works:

class myclass1 {     // ... stuff goes here ... }  class myclass2 extends myclass1 {     // ... stuff goes here ... }  class main {     public static void main(string[] args) {         myclass1 object = new myclass2();     } } 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -