What are access modifiers in Java?

Hari Vinayak
Hari Vinayak

Posted On: Dec 18, 2020

 

The four types access modifiers in Java are as follows:

  1. private
  2. default
  3. protected
  4. public

private indicates that The access level of a private modifier is only within the class.

default indicates that The access level of a default modifier is only within the package.

protected indicates that The access level of a protected modifier is within the package and outside the package through child class.

public indicates that The access level of a public modifier is everywhere.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    HCL Java Developer Interview Questions

    What is Multithreading in Java?

    Multithreading is a programmable approach to achieve multitasking. Multithreading in Java is a process of executing multiple threads cumulatively. A thread is the smallest unit of processing which is ...

    HCL Java Developer Interview Questions

    What use of intern() method in String?

    In Java, intern() is a native method of the String class. The String.intern () returns a reference to the equal string literal present in the string pool. The intern () method is applicable to String ...

    HCL Java Developer Interview Questions

    What is Collection Framework?

    A Java collection framework is an architecture that was added to Java 1.2 version. The Collection Framework provides a well-designed set of classes and interfaces for storing and manipulating a group ...