In this tutorial, we will discuss the private keyword in java programming language
private is a Java keyword used to declare a member’s access as private(access modifier). When we declare access modifier as private, we can only access within the class. We can not access from other class or subclass.
This keyword can be used to define a class, a method or a variable, given below
The private access modifier can be applied to data members or member variable. It is declared in the enclosed class.
the syntax of private variable
<access modifier> <data_type> <variable_name>;
Example of the private variable
private int age;
when a method is marked as private, it cannot be executed from outside of the class. Access only from within the class.
the syntax of the private method
<access modifier> <data_type> <method_name>;
private void move()
When a class is declared as private, it can be accessed only from within the enclosing class. It cannot be accessed from outside class like variables and methods.
the syntax of private class
<access modifier> <class> <class_name>;
Example
private class first_action{ }
There are other Java language keywords that are similar to this keyword
Suggested for you
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…