Keyword in Java

The private keyword in Java programming language

The private keyword in Java programming language

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

private variable

The private access modifier can be applied to data members or member variable. It is declared in the enclosed class.

  • a private variable accessed only from within it’s enclosed class

Syntax

the syntax of private variable

<access modifier> <data_type> <variable_name>;

Example

Example of the private variable

private int age;

private method

when a method is marked as private, it cannot be executed from outside of the class. Access only from within the class.

Syntax

the syntax of the private method

<access modifier> <data_type> <method_name>;

Example

private void move()

Private class

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.

Syntax

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

public keyword in Java

protected keyword in java

 

Suggested for you

access modifier In the Java programming language

Data type and variable in Java language

The method in Java language

Keywords in Java language

Keywords in C++ language

Keywords in C language

Keywords in Python language

The public keyword in Java programming language
The protected keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

1 month ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

9 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

9 months ago