Find your content:

Search form

You are here

Subclass doesn't have visibility to abstract base class member variable

 
Share

I'm trying to create a subclass of BaseClass (SecondClass). SecondClass is extending BaseClass.

BaseClass is a abstract class, which has a member variable sList.

Since I am extending BaseClass in my SecondClass, I guess we can use sList here in SecondClass.

But when I am saving the SecondClass, I am gating

Saving Error : member variable not visible for assignment

Any Idea?

public with sharing class SecondClass extends BaseClass {

   private void init() {

         //this.sList = new SelectorList();
   }


}



public abstract class BaseClass {

   public SelectorList sList {get; private set;}

}

Attribution to: SFDC Geek

Possible Suggestion/Solution #1

The problem is that you are using the private access modifier on your setter in your base class.

private
This is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private.

You need to use protected or public on your setter to be able to call it in a subclass.

protected
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables. Note that it is strictly more permissive than the default (private) setting, just like Java.

public
This means the method or variable can be used by any Apex in this application or namespace.

Documentation on Access Modifiers can be found here.


Attribution to: Alex Tennant
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33941

My Block Status

My Block Content