- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Public Keyword in Java
Public Access Modifier - Public
A class, method, constructor, interface, etc. declared public can be accessed from any other class. Therefore, fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.
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.
- Related Articles
- public access modifier in Java
- New keyword in Java
- This keyword in Java
- super keyword in Java
- final keyword in Java
- instanceof Keyword in Java
- Private Keyword in Java
- Protected Keyword in Java
- static Keyword in Java
- synchronized Keyword in Java
- transient Keyword in Java
- volatile Keyword in Java
- Java static keyword
- Java strictfp keyword
- static Keyword in Java programming

Advertisements