Can we override a protected method in Java?

Yes, the protected method of a superclass can be overridden by a subclass. If the superclass method is protected, the subclass overridden method can have protected or public (but not default or private) which means the subclass overridden method can not have a weaker access specifier.


class A {
   protected void protectedMethod() {
      System.out.println("superclass protected method");
class B extends A {
   protected void protectedMethod() {
      System.out.println("subclass protected method");
public class Test {
   public static void main(String args[]) {
      B b = new B();


subclass protected method

Updated on: 03-Jul-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started