当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Right access modifier for a Template Methods in a Parent Class

问题描述:

Can I make a Template method in an Parent Class private

I want to use the template Pattern in overriding a method in a child class so when the method is called in the Parent Class, the overrided non in the Child Class is executed, But I am not sure which access modifier to use to declare the method in the Parent class, I want to make the Method private or protected if possible

网友答案:

You cannnot access the private members of parent class. And if You make it protected then you cannot access from the non-child classes outside the package.

So if you need to acces the method from anywhere use public modifier. If you only need to access within the package use protected

分享给朋友:
您可能感兴趣的文章:
随机阅读: