Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Enforce setting private variable in subclass with abstract method

802930Nov 7 2011 — edited Nov 9 2011
Hi,

Is this something that is common usage/practice?:
public abstract class Base {
    private int importantPrivateVariable = setImportantPrivateVariable();
    protected abstract int setImportantPrivateVariable();
}
I would like to enforce the extender of the class to set a private variable, but as there is no abstract variable in java, I can only use a method for it.

Thanks,
lemonboston

Edit: the variable could be protected as well, I suppose this is not important here, but correct me if I am wrong
This post has been answered by jduprez on Nov 7 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2011
Added on Nov 7 2011
7 comments
1,183 views