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

 byte  in Java Language

 int  in Java Language

long  in Java Language

 float  in Java Language

char  in Java Language

 void  in Java Language

try  in Java Language

Catch in Java Language

implements  in java Language

public  in Java Language

static  in Java language

Volatile  in Java Language

Package  in Java Language

class  in Java Language

boolean  in Java Language

break in Java Language

do  in Java Language

double  in Java Language

This  in Java Language

final  in Java Language

switch  in Java Language

interface  in Java Language

extends  in Java language

 

Suggested for you

 Java language Keywords

C language Keywords

 Python language Keywords

keywords in C language

Finally  in Java 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

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago