Answered Questions

  • Can we declare class as protected?

    what is the scope for this class?

    Star Read Best Answer

    Editorial / Best Answer

    dipl. ing. Dan  

    • Member Since Mar-2006 | Mar 24th, 2006

    Some people might get confused by the many posts. The correct answer to the question "can we declare class as protected?" is YES, BUT only as an inner class. A 'normal' class cannot be protected or private.

    // 'Normal' class - only default or public allowed

    public class ProtectedOrNot {

      // Inner class - public, default, protected, private allowed

      protected class InnerClass {


      public static void main(String[] args) {




    • Sep 21st, 2017

    We cannot declare primary classes as protected for primary classes only "public","final","abstract" are allowed. But point to be noted you can declare inner classes as protected. ...


    • Jul 8th, 2017

    We cannot declare class as protected and private it gives compile time error.
    Illegal modifier for the class TestClass; only public, abstract & final are permitted