
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Scope of Public Access Modifier in Java
The public modifier has the widest scope. When a class or its members declared public they are accessible from everywhere. A default class or its members are available to any other class in the same package.
However, if the public class we are trying to access is in a different package, then the public class still needs to be imported. Because of class inheritance, all public methods and variables of a class are inherited by its subclasses.
Example
The following function uses public access control −
public static void main(String[] arguments) { // ... }
The main() method of an application has to be public. Otherwise, it could not be called by a Java interpreter (such as java) to run the class.
Advertisements