java - Variable declared in abstract class not found in child implementation -
planning on having multiple classes extended super class, , sake of simplicity i've tried declare common variables in super class need assign them value in sub classes, child classes aren't recognising variables.
abstract class:
public abstract class abstractapiservice { public string apidocumentation; //selected api documentation location }
example implementation:
@path("/transport") @stateless public class transportapi extends abstractapiservice { apidocumentation = "http://docs.transportapi.com/index.html?raml=http://transportapi.com/v3/raml/transportapi.raml"; //desired functionality: ... }
as far can see, legal , seems should work, netbeans isn't recognising variables.
superclass variables accesible superclass context only, meaning inherit variables directly accesible referencing them reserved word "this
". in order work superclass variable must declared public or protected
notice if have local variable inside child class same name superclass variable "this
" reference local varaible, in order use superclass varaible in case you'll have use reserved word "super
"
@path("/transport") @stateless public class transportapi extends abstractapiservice { this.apidocumentation = "http://docs.transportapi.com/index.html?raml=http://transportapi.com/v3/raml/transportapi.raml"; //desired functionality: //access superclass variable string value = this.apidocumentation; //or super.apidocumentation ... }
however not recommend access these varaibles directly, provide getter/setter method , access them those.
Comments
Post a Comment