Restrictions for declaring a class in java
Restrictions for declaring a class in java :-
A class never be declared by private and protected access specifier. i.e. If we do then we directly get compile time error.
-> When we declare a java class through public access specifier at that time file name must be match with the class name.
-> When we declare the java class through no access specifier at that time file name may match with the class name or may not.
* public class <class name>
it will access in the same package and also different package.
* class < class name >
it will access only same package not different.
* If we declare a class in private.
private class X
{
public static void main(String args[])
{
System.out.println("A class never be declare in private");
}
}
* If we declare a class in protected.
protecterd class y
{
public static void main(String args[])
{
System.out.println("class never be declare protected");
}
}
Restrictions for declaring a class in java
for more detail follow my Instagram id - https://www.instagram.com/asitmaharana10/
Thank you.
Post a Comment
Post a Comment