Access Modifiers

Ads
 
Tutorials   
Java/JDK 15 upcoming new features JDK/Java 15 Tutorials How to install OpenJDK 8 in Ubuntu 18.04? Java Interpreter is used for which purpose? Java program to read a text file and write to another file How to Serialize and Deserialize Array List in Java? What are the prerequisites for learning Java? How to replace all occurrences of a string in JavaScript? How to convert a stack trace to a string? Example code of reading file line by line in Java with Apache Commons IO library How to store unique values in Java using Set? java.nio ShortBuffer Example How to use Java Path class? Java NIO Package Tutorial How to limit object creation in Java? Java 11 String lines function example to split it in lines Top upcoming features of JDK 11 Java/JDK 11 Tutorial How to install JDK 10 in Ubuntu 18.04? Install JDK 10 on Windows Java 10 features Processing large file in Java Learning Java for non programmers Why You Should Learn Java in 2018? Installing JDK 9 on Windows 10 How to convert binary to decimal in Java? How to add two numbers in Java? What is Applet in Java with Example? What is nested class in Java with Example? Exception handling in Java Programming Examples What is Constructor Overloading in Java? How to display image in Swing? What is Java programming used for? How to create custom exception in Java? How to set CLASSPATH in Java? What is Multithreading in Java? IO Streams in Java with Examples How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner

Access Modifiers

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods.

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods.

Access Modifiers

     

Access Modifiers : Access modifiers are used to specify the visibility and accessibility of a class, member variables and methods. Java provides some access modifiers like: public, private etc.. These can also be used with the member variables and methods to specify their accessibility. 

  1. public keyword specifies that the public class, the public  fields and the public methods can be accessed from anywhere.
     
  2. private: This keyword provides the accessibility only within a  class i.e. private fields and methods can be accessed only within the same class.
      
  3. protected: This modifier makes a member of the class available to all classes in the same package and all sub classes of the class. 
      
  4. default : Its not a keyword. When we don't write any access modifier then default is considered. It allows the class, fields and methods accessible within the package only.

Ads

Ads