What is public in java
What is public in java
-> In Java public is a access specifier or access modifier and also a keyword.
-> In java there are 4 access specifier are available.
1.Public.
2.Protected.
3.Private.
4.No access.
-> In java the default access specifier is no access.
-> When the member of the class is public then it is freely invoked within the same package or outside the package either the class is inherited or not inherited.
What is public in java |
Program for public :-
public class m
{
public void display()
{
System.out.println("I Like Java");
}
public static void main(String args[])
{
m s=new m();
s.display();
}
}
output :-I Like Java
public class n extends m
{
public static void main(String args[])
{
System.out.println(" i Am Asit");
n a=new n();
a.display();
}
}
output :- i Am Asit
I Like Java
This program show that if the program is public we can access the program within that class and also
without that class.
If the program is public then we can access the program within that package and also without that package.
for more detail follow my Instagram id - https://www.instagram.com/asitmaharana10/
Thank you.
Post a Comment
Post a Comment