Private Class Declaration

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praveen2gupta
    New Member
    • May 2007
    • 200

    #16
    class is having only Two access Modifiers

    1. default (neet not to write)
    2. Public

    any other access modifiers are not allowed with classes.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #17
      Originally posted by DeMan
      .....(does that include me)
      You do that, you'd be banned before you even hit the Submit Reply button.

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #18
        Originally posted by praveen2gupta
        class is having only Two access Modifiers

        1. default (neet not to write)
        2. Public

        any other access modifiers are not allowed with classes.
        Here we go again, unless it's inside another class

        [CODE=java]package x;
        class a {
        private class b {
        }
        protected class c {
        }
        }[/CODE]

        Comment

        • AtulTiwari
          New Member
          • May 2007
          • 23

          #19
          Originally posted by r035198x
          Here we go again, unless it's inside another class

          [CODE=java]package x;
          class a {
          private class b {
          }
          protected class c {
          }
          }[/CODE]

          This time You are all Right Dear r0

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #20
            Just to sum it all up; there are top level classes and nested classes. Top level
            classes have either package scope or they are public.

            Nested classes can be static or not which is not relevant for this discussion.
            Nested classes can either be private, protected, package scope or public.
            Anonymous classes (e.g. those small Listener or Observer classes) have to be
            made visible by the surrounding class otherwise they don't exist according to the
            outside world, whatever that may be.

            It doesn't make sense for top level classes to be private because nothing else
            can reach them. The same goes for protected top level classes, i.e. only the
            class itself can reach it or a subclass thereof. But something else has to start
            the whole thing going but it isn't allowed to even point its finger at it, nor at a
            subclass thereof.

            kind regards,

            Jos

            Comment

            Working...