What is the public modifier
This article mainly introduces "what is the public modifier". In the daily operation, I believe that many people have doubts about what the public modifier is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the questions of "what is the public modifier?" Next, please follow the editor to study!
1. Any other class can access classes, methods, constructors, and interfaces declared as public.
2. If the public classes that visit each other are distributed in different packages, you need to import the package where the corresponding public classes are located. Because of class inheritance, all public methods and variables can be inherited by their subclasses.
Example
Public class demo1 {public static void main (String [] args) {Person p1 = new Person (); p1.fn (); System.out.println (p1.a); / / 100 System.out.println (p1.scorce); / / 12.5 / / System.out.println (p1.abc); / / unable to access error report} class Person {int a = 100 / / visible in the same package without any modifiers. Public float scorce = 12.5f; / / visible to all classes. Using objects: classes, interfaces, variables, methods private double abv = 545.6487485; / / visible within the same class. Public void fn () {System.out.println ("I am the fn function");} at this point, the study of "what is the public modifier" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!