Sunday, January 31, 2021

Access Specifiers

 There are four types of access specifiers in java:

1. Private:The private access modifier id accessible only within class.

2. Default: If you don't use any modifier, It is treated as default by-default. The default modifier is accessible only within package.

3. Protected: The protected access modifier is accessible within package and outside package but through inheritance only.

Note:The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.

4. Public: The public access modifier is accessible everywhere. it has the widest scope among all other modifiers.

                            OR

public: Accessible to all. Other objects can also access this member variable or function.
private: Not accessible by other objects. Private members can be accessed only by the methods in the same class. Object accessible only in class in which they are declared.
protected: The scope of a protected variable is within the class which declares it and in the class which inherits from the class (Scope is class and subclass).
Default: Scope is Package Level. We do not need to explicitly mention default as when we do not mention any access specifier it is considered as default.

No comments:

Post a Comment

String coding questioon

  How do you reverse a given string in place? ( solution ) How do you print duplicate characters from a string? ( solution ) How do you chec...