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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值