Results 1 to 2 of 2
  1. #1
    muni bhaskar is offline Member
    Join Date
    Dec 2016
    Posts
    4
    Rep Power
    0

    Default why classes cannot be private and protected

    HI,
    I am new to java . I am wondering why we cannot use private and protected classes. is it something related to access modifiers rule. when should i use override annotation and what is the importance of override annotations

    thanks in advance,

    Bhaskar.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: why classes cannot be private and protected

    What do you mean by "private and protected classes"?
    I can declare a class private or protected, it's perfectly legal.

    As for @Override, it lets the compiler warn you that you made a typo:
    Java Code:
    @Override
    public String ToString() {
        return "some string";
    }
    The above would be a compilation error. Without @Override you wouldn't know you had an issue until runtime, and possibly not for a while.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Initializing Private Classes.
    By Newjav13 in forum New To Java
    Replies: 6
    Last Post: 07-18-2015, 04:56 PM
  2. modifier [public|default|private|protected] ?
    By R03 in forum New To Java
    Replies: 2
    Last Post: 05-06-2014, 03:07 PM
  3. Replies: 1
    Last Post: 02-10-2011, 04:43 AM
  4. Top level Protected Classes
    By Jithu in forum New To Java
    Replies: 2
    Last Post: 10-06-2010, 01:28 PM
  5. Replies: 3
    Last Post: 03-14-2009, 07:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •