Access level of the class:
Class access level is like a tree, want to reach the top of the tree, to climb slowly from under the tree. The branches under the tree can see the branches next to them. In Java, the methods of a class also have a level relationship.
Public access levels:
A class with the "public" modifier is declared as the access level of the State, that is, preceded by the name of the class with the publicly modifier. The class is decorated with the public modifier, which means that any class in any package can access the class. But pay attention to the problem of different packages. Although it can be accessed by any class in the package, reference statements are also required under different packages. The following code shows how to use the public modifier to decorate a class.
Create a Package A
Package A;
Import b.*;
The test class describes a modifier that modifies a class
Pubblic class Test
{
Main entry method of Java program
public static void Main (Strin[]args)
{
Creating an object instance of Test1
test1 T1 =new test1
Assigns the value of the EMP to the string type S
String s =t1.emp;
Print and display the results
System.out.println (s);
}
}
Create a Package
Package B;
public class Test1
{
String emp = "Member variable in different packages"
}
The default access level:
Classes with a default access level are declared without any modifiers, and the default access level can be treated as package-level access and can only be used by classes under the same package. The default access level is similar to the exposed access level, where the default access level does not make it possible to access classes under different packages, only those under the same package.
The test class describes the default level of class
Class Test
{
...//Method body
}
Create a Package A
Package A;
Import b.*;
public class Test
{
public static void Main (string[] args)
{
Test1=new test1 ();
String s=t1.emp;
System.out.println (s);
}
}
Create a Package
Package B;
Class Test1
{
Striing emp= "variables in different members"
}
Access level of the class