The Java language defines the 6 common modifiers of public, protected, private, abstract, static, and final, as well as 5 less commonly used modifiers, and below is an introduction to the 11 Java modifiers:
1.public
Working with objects: classes, interfaces, members
Descr
Available modifiers for classes, methods, member variables, and local variables
Modifiers
Class
Member Methods
Construction method
Member variable
Local variables
Abstract
Y
Y
_
_
_
Static
_
Y
_
Y
_
Public
Y
Y
Y
Y
_
Protected
_
Y
Y
Y
_
The protected methods and properties defined in a class are the same as the default permission methods and properties. For example, a class of protected methods and properties outside the package is not accessible through the class instance (can you access the default permissions of a class outside of the package method and properties?). Of course not), which is why you cannot invoke its protected methods and properties anywhere outside of the package
1. Modifier A in Java. Permission modifiersPrivate, default, Protected,publicB. Status modifierStatic,finalC. Abstract modifiersAbstract2. Class modifiersPublic (access control), declare a class as a common class, he can be accessed by any object, the main class of a program must be a public class, and a. java file can only have one common class, and the file name must be the same as the class.By default ,
There are only three access modifiers public,protected and private in Java.
1, if you do not write any modifiers, the default is "package access permissions." The equivalent of all other classes and methods within the package is public, and the classes and methods outside the package are private. Because the grace of a compilation unit (a
returned type must always be the same as the return type of the overridden method, otherwise it cannot be called overriding but overloaded. (3), the restriction of the access modifier must be greater than or equal to the access modifier of the overridden method ( Public>protected>default>Private) (4), the overriding method must not throw a new check exception or a more generalized check exception than the overridden method declaration. For example: A
class* 3) a large:* 3.1) The subclass method has access rights greater than or equal to the parent class's*/The parent class is large, the sub-class is smallClass coo{void Show () {}Double Test () {return 0.0;}Doo Sayhi () {return null;}Public Coo Say () {return null;}}Class Doo extends coo{int Show () {return 1;}//Compile error, must be equal when voidint Test () {return 0;}//Compile error, basic type must be equalCoo Sayhi () {return null;}//Compile error, reference type must be less than or
Access Control modifiersIn Java, you can use access controls to protect access to classes, variables, methods, and construction methods. JAVAV supports 4 different types of access rights.
default (That is, by default, nothing is written): it is visible within the same package, and no modifiers are used. Use objects: classes, interfaces, variables, methods.
Private : Visible within the same clas
Modifiers in the Java language----------------------------------------------------------------------------------------------The available modifiers for classes, methods, member variables, and local variablesAccess Control Level classifications:Exposure level, protected level, default level, private level------------------------------------------------------------
console does not work.
The role of the jar file:
1. Easy for users to run a project quickly.2. Provide tool classes to others in the form of a jar package.
If you use a class inside a jar package, you must first set the Classpath path.JRE = jvm+ Core Class Librarypackage qq;import javax.swing.*;class Demo9 { publicstaticvoidmain(String[] args) { System.out.println("QQ程序.."); new JFrame("QQ程序"); frame.setSize(400,500); frame.setVisible(true//设置窗口
file comparison,Here's a look at the differences in Java:First we'll look at the addition of this code in Java to the public interface Testsorbuilder, and then we'll see, Java.util.listWe will then find the TESTQ code in 697 rows, so adding more than 600 lines of code will be added to the repeated modifier. See:Then you will find, in the below, the difference, see:For example, add the Internal_static_trade
Available modifiers for classes, methods, member variables, and local variables
Modifier
Class
Member Methods
Construction method
Member variables
Local variables
Abstract
Y
Y
_
_
_
Static
_
Y
_
Y
_
Public
Y
Y
Y
Y
_
Protected
_
Y
Y
Y
_
Private
)
Objective:transforms the interface of one class into another interface that the customer Wants. a D a P T e r mode makes it possible for those classes that would otherwise not work together because of incompatible interfaces to work Together. Principle:Target Interface ( Target): The interface that the customer Expects. a class that needs to be adapted ( Adaptee): A class or adapter class that needs to be adapted. Adapter ( Adapter): Converts the original interface into a target interface
given an initial value and cannot be modified
Method Modifiers
Public
It can be accessed from all classes
Protected
It can only be accessed from this class and its subclasses
Private
It can only be accessed from this class
Abstract
No method body, belongs to an abstract class
Final
Subclasses cannot overwrite it
Static
is bo
has been the concept of these modifiers is not very clear, while the intern assessment just ended empty time to study.1. Modifiers that can modify member variables and member methods have three plus one default. Their scope uses the following:Scope Current class same package descendant class other packagePublic√√√√Protected√√√xFRIENDLY√√XX (default)Private√xxx2. Modifie
public access is not restricted.-----------------------------------------------Special Note: In C # If the class internal members (methods, properties, fields, etc.) do not write any adornments Fuzeme think private;The default is internal if the access modifier of the Class (class) is not written.Assemblies can be understood as current projects, such as when building a 3-tier framework, a solution will have multiple projects (presentation layer, business logic layer, data access layer ...). ),
//Math.sin (12.34); //Math.tan (12.34); //... //exponential function//Math.exp (12.34); //Math.log (12.34); //... //Rounding method, rounding up , rounding up and rounding downSystem.out.println (Math.rint (12.74));//Who are you close to?System.out.println (Math.floor (12.74));//take the smallest integerSystem.out.println (Math.ceil (12.34));//take maximum integerSystem.out.println (Math.Round (12.34));//serious rounding, returns a long integerSystem.out.println (Math.min (
* Declaration of the class
[Modifier] Class
Modifiers: optional, for specifying access rights, the available values are public,abstract and finnal.
Class name: In general, the first letter is required to be capitalized.
Extends parent class name: optional, which specifies which parent class the class to be defined inherits from.
Implements interface list: used to specify which interfaces the class implements.
A class that is declared public ind
The permission modifiers in the 1.Java language mainly include private,public, default, Protected, which control access to member variables and member methods of classes and classes . permission modifiers in the Java languageSyntax formatting when modifying a variable with a permission modifier:Puclic type attribute
package
C: If there is no package, the default is the No bag name
(5) Compile and run with package
A: Manual Type
B: Auto-type
"Javac–d. Helloworld.java "
3. Guide Package
(1) Every time we use a class with a package, very troublesome, this time provides a keyword
(2) Format:
A:import Package Name: class name; "Recommended"
B:import Registration: *;
(3) Order of Package,import,cl
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.