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) {

      }

    }

    vishal

    • 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. ...

    Srinu

    • 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

  • What is difference between abstract class and interface

    UMA

    • Jan 22nd, 2013

    polymorphism are mainly two types static polymorphism(corresponding method will bind at the time of compiling) dynamic polymorphism(corresponding method will bind at the run time) Static polymorphi...

    sharoon

    • Sep 26th, 2012

    In a very simple and high level, Interface is something to tell a guy, Hey X, you should to all these if you need me whereas abstract class tells Hey X, you should do this alone need not to disturb others.