+ 2

Can we make the java class private

If we can then where and what is the use

10th Apr 2020, 5:23 AM
Digvijay Singh Rathore
Digvijay Singh Rathore - avatar
5 Answers
+ 2
The private access modifier is accessible only within the same class.
10th Apr 2020, 7:13 AM
Mahmudul Hasan
Mahmudul Hasan - avatar
+ 1
Yes you can declare a class with private access specifier. But not in main class. You can declare private in inner classes only. Below a example class Outer_Demo { int num; // inner class private class Inner_Demo { public void print() { System.out.println("This is an inner class"); } }
10th Apr 2020, 6:08 AM
Mahmudul Hasan
Mahmudul Hasan - avatar
+ 1
What is the use of making it private
10th Apr 2020, 7:09 AM
Digvijay Singh Rathore
Digvijay Singh Rathore - avatar
+ 1
we cannot declare top level class as private.Java allows only public and default modifier for top level classes in Java. Inner classes can be private.
10th Apr 2020, 11:11 AM
narayanaprasad
narayanaprasad - avatar
0
Thanks
10th Apr 2020, 7:14 AM
Digvijay Singh Rathore
Digvijay Singh Rathore - avatar