private_Keyword

private Java Keyword with Examples

The private keyword is an access control modifier that may be applied to a class, a method or a field (a variable declared in a class).

Key points about private Java Keyword

  • A private class member cannot be accessed from outside the class; only members of the same class can access these private members.
  • A class cannot be a private except inner classes because inner classes are nothing but again members of outer class. So members of a class (field, method, constructor and inner class) can be private but not the class itself. We can’t create subclasses to that class which has only private constructors.
    private Java Keyword Example
    Below diagram demonstrates the usage of private access modifier and it’s visibility:

Summary

A private (inner) class, method or field may only be referenced from within the class in which it is declared. It is not visible outside the class or to subclasses.
The default access for all class members is package access, meaning that unless a specific access control modifier is present the class members are accessible from within any class in the same package.

全部评论

相关推荐

投递长鑫存储等公司8个岗位
点赞 评论 收藏
分享
屌丝逆袭咸鱼计划:心态摆好,man,晚点找早点找到最后都是为了提升自己好进正职,努力提升自己才是最关键的😤难道说现在找不到找的太晚了就炸了可以鸡鸡了吗😤早实习晚实习不都是为了以后多积累,大四学长有的秋招进的也不妨碍有的春招进,人生就这样
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务