Thursday 27 April 2017

In Java protected Keyword

In Java protected Keyword

Protected specifiers allows the class itself, subclasses, and all classes in the same package to access the members. You should use the protected access level for those data members or member functions of a class, which you can be accessed by subclasses of that class, but not unrelated classes. You can see protected members as family secrets–you don’t mind if the whole family knows, and even a few trusted friends but you wouldn’t want any outsiders to know. A member can be declared protected using keyword protected.

public class Student
{
         protected int age;
         public String name;
         protected void protectedMethod()
        {
                  System.out.println("protectedMethod");
        }
}

Visit our site for Registration java coaching in jaipur

0 comments:

Post a Comment