- 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
What is Default access level in Java?
The default access level is available when no access level is specified. All the classes, data members, methods etc. which have the default access level can only be accessed inside the same package.
A program that demonstrates the default access level in Java is given as follows:
Example
class Employee { int empno; String name; void insert(int e, String n) { empno = e; name = n; } void display() { System.out.println("Employee Number: " + empno); System.out.println("Name: " + name); } } public class Demo { public static void main(String[] args) { Employee emp = new Employee(); emp.insert(105, "James Nortan"); emp.display(); } }
Output
Employee Number: 105 Name: James Nortan
Now let us understand the above program.
The Employee class is created with data members empno, name and member functions insert() and display(). The Employee class and the data members empno, name have the default access control. A code snippet which demonstrates this is as follows:
class Employee { int empno; String name; void insert(int e, String n) { empno = e; name = n; } void display() { System.out.println("Employee Number: " + empno); System.out.println("Name: " + name); } }
In the main() method, an object emp of class Employee is created. Then insert() method is called with parameters 105 and “James Norton”. Finally the display() method is called. A code snippet which demonstrates this is as follows:
public class Demo { public static void main(String[] args) { Employee emp = new Employee(); emp.insert(105, "James Nortan"); emp.display(); } }
- Related Articles
- What is the scope of default access modifier in Java?
- default access modifier in Java
- What are private, public, default and protected access Java modifiers?
- What is the default access for a class in C#?
- What are the differences between protected and default access specifiers in Java?
- What is the default access for a class member in C#?
- What is the use of default methods in Java?
- What are access modifiers and non-access modifiers in Java?
- What are Default Constructors in Java?
- What is the purpose of a default constructor in Java?
- What is the scope of public access modifier in Java?
- What is the scope of protected access modifier in Java?
- What is the scope of private access modifier in Java?
- What are Default Methods in Java 8?
- Access and Non Access Modifiers in Java
