`
allwit
  • 浏览: 18868 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Java Modifiers

阅读更多

Java Modifiers 大体可以分为两类:

     1) Access modifiers : public, protected, default, private

     2) Non- Access modifiers : strictfp, final and abstract

        Below are the modifiers for key word class:
       1.public: The class can be used anywhere

       2.abstract: The class is an abstract class and no instance of it can be generated

       3.final: The class cannot be inherited

       4.strictfp(strict floating point): Make the floating-point arithmetic in the class evaluated strictly. This ensures the interoperability of the floating-point calculation.

 

The following table shows what Access Modifiers are appropriate for classes, nested classes, member variables, and methods:

  Class Nested class Method, or Member variable Interface Interface method signature publicprotected package (default) private
visible from anywhere same as its class same as its class visible from anywhere visible from anywhere
N/A its class and its subclass its class and its subclass, and from its package N/A N/A
only from its package only from its package only from its package only from its package N/A, default is public
N/A only from its class only from its class N/A N/A

If a class has public visibility, the class can be referenced by anywhere in the program. If a class has package visibility, the class can be referenced only in the package where the class is defined. If a class has private visibility, (it can happen only if the class is defined nested in an other class) the class can be accessed only in the outer class.

If a variable is defined in a public class and it has public visibility, the variable can be reference anywhere in the application through the class it is defined in. If a variable has package visibility, the variable can be referenced only in the same package through the class it is defined in. If a variable has private visibility, the variable can be accessed only in the class it is defined in.

If a method is defined in a public class and it has public visibility, the method can be called anywhere in the application through the class it is defined in. If a method has package visibility, the method can be called only in the same package through the class it is defined in. If a method has private visibility, the method can be called only in the class it is defined in.

分享到:
评论

相关推荐

    Java Class and Method Modifiers

    Java Class and Method Modifiers

    JavaObjectModel-notes.pdf

    ### Java对象模型基础知识点 #### 一、Java对象模型概览 Java对象模型是Java编程语言的核心组成部分之一,它定义了如何在Java中创建、组织和管理类与对象。Java对象模型强调面向对象编程的基本原则:封装、继承、...

    Programming with Java.ppt

    3. Modifiers:Java语言使用修饰符(modifiers)来指定数据、方法和类的属性和行为。 4. Statements:Java语言的语句(statements)代表一个动作或一系列动作,例如System.out.println("Welcome to Java!")。 Java...

    Learning-Java-Beginner-Level:开始学习 Java 时包含的练习

    --> JAVA IDENTIFIERS:- ... JAVA MODIFIERS:- 像其他语言一样,可以通过使用修饰符来修改类、方法等。 有两类修饰符: 访问修饰符:default、public、protected、private 非访问修饰符:final、abstract、strictfp

    JAVA对象模块.rar

    6. 访问修饰符(Access Modifiers): Java提供了`public`, `private`, `protected`和默认的访问修饰符,用来控制类的属性和方法的可见性。例如,`private`表示仅限类内部访问,`public`则允许任何地方访问。 7. ...

    C、Java和Python的BNF范式

    在本资源中,我们关注的是C、Java和Python这三种流行的编程语言的BNF范式。 首先,让我们详细探讨C语言的BNF范式。C语言的语法严谨且层次分明,它的BNF范式主要涵盖了程序的基本组成部分,如声明(declarations)、...

    Java中的类和对象总结

    ### Java中的类和对象总结 #### 一、类与对象的概念 在面向对象编程中,类(Class)和对象(Object)是两个核心概念。类是对象的抽象模板,它定义了对象的数据结构(即属性)和行为(即方法)。而对象则是类的具体...

    论C#与Java之异同

    7. **Access Modifiers** - **访问修饰符**: C#和Java都有类似的关键字来控制类成员的可见性,但具体关键字可能不同。 8. **Reflection** - **反射**: 两种语言都支持反射功能,用于在运行时获取类的信息和动态...

    Java_java.zip

    7. **访问修饰符** (access modifiers):如`public`、`private`、`protected`,控制类、变量和方法的可见性。 8. **接口** (interface):定义一组方法签名,但不包含实现,用于多态性。 9. **注释** (comments):...

    Java基础英语词汇大全

    10. **访问修饰符(Access Modifiers)**:如public、private、protected,控制类成员的访问权限。 11. **抽象类(Abstract Class)**:不能实例化的类,通常用于定义接口或提供部分实现。 12. **静态(Static)**...

    java知识点总结

    - **访问修饰符 (Modifiers)**:如`public`,表示该类可以被任何其他类访问。 - **主方法 (Main Method)**:每个Java应用程序都有一个入口点,即`public static void main(String[] args)`方法。这是程序启动时调用...

    《Java面向对象程序设计(第2版)》

    书中还涵盖了接口(Interface)、抽象类(Abstract Class)、访问修饰符(Access Modifiers)、包(Package)等高级主题。此外,异常处理(Exception Handling)也是Java编程中不可或缺的一部分,它允许程序优雅地...

    Java入门——Java修饰词总结

    Java作为一门广泛使用的编程语言,拥有丰富的语法结构和关键字,其中修饰词(modifiers)是Java语言中的重要组成部分,用于限定类、方法、字段等的访问级别、生命周期以及特性。以下是对Java中11个修饰词的详细介绍...

    JAVA入门 日文版

    修飾子(Modifiers) - **修飾子の種類**: - **アクセス修飾子**: `public`, `protected`, `private`, `default`(パッケージプライベート) - **非アクセス修飾子**: `static`, `final`, `abstract`, `...

    JAVA语言学习课件

    面向对象编程是Java语言的核心特性,它是一种将现实世界中的实体抽象为类,然后通过类来创建和操作对象的编程范式。本节将深入探讨面向对象的程序设计,包括类和对象的概念,对象的创建和使用,以及信息的封装和隐藏...

    java常用英文单词

    16. **访问修饰符(Access Modifiers)**:如 `public`、`private`、`protected` 和默认修饰符,控制类、方法和变量的访问权限。 17. **静态(Static)**:修饰符,用于声明类级别的成员,而不是对象级别的。如 `...

Global site tag (gtag.js) - Google Analytics