java - How to access the members of the concrete class using the reference variable of the abstract class -


my abstract class has 3 methods. concrete class extends abstract class has price,name,packing. how can access properties using reference variable of abstract class having instance of concrete class. directly can't access of set methods of concrete class using reference variable. there special pattern problem???? according design, have assign instance of concrete class reference variable of abstract class. can't create direct object of concrete class.

with reference abstract class alone, can't much. however, can type cast corresponding concrete class.

eg: if have class , class b extends class a, can like

if(obj instanceof b){ //type cast obj class b here , call respective method of b ((b)obj).concreteclassmethod(); } 

here obj reference variable of abstract class a. way, can access method (or public property) of class b, keeping reference, class a.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -