public private protect
public Private
2023-09-27 14:23:51 时间
public 公有 使用public意味着声明public之后的成员对每个人都是可用的
private 私有 除非必须公开底层实现细目,否则就应该将所有的域指定为private
protect 继承访问权限
通过继承可以利用一个现有类-我们将之称为基类,让偶将新成员添加到现有类中,而不必碰现有类,还可改变现有类的行为
为了从现有类中继承需要声明extends(扩展) 了一个现有类
继承时,先初始化基类,再初始化继承类
示例:
//base class
package Thingking_in_java.ch6.ch6_03.debug; import static net.feilong.util.Print.*; public class Debug{ public Debug() { print("you is success\n"); } public static void main(String[] args) { } }
//inherit class
package Thingking_in_java.ch6.ch6_04; import Thingking_in_java.ch6.ch6_03.debug.*; public class Foo extends Debug{ public Foo() { System.out.println("FOO constructor"); } public void chomp() { new Debug(); } public static void main(String args[]) { Foo foo = new Foo(); foo.chomp(); } }
/* output:
you is success 初始化基类
FOO constructor 初始化现有类
you is sucess
*///~
相关文章
- Why use a public method in an internal class?
- Why use a public method in an internal class?
- Make sure that the controller has a parameterless public constructor.
- public static float CompareExchange(ref float location1,float value,float comparand)
- PHP public、private、protected 修饰符
- C++中public、protected、private的差别
- MySQL 8 Public Key Retrieval is not allowed 错误的解决方法
- 【转】深入理解C++中public、protected及private用法
- Public CMS二次开发过程,如何使用多个数据源
- C#中new的两种用法"public new"和"new public"
- SwiftUI 内功之Swift 中的访问级别private, file-private, public, internal, open
- Locations for Public Frameworks
- public var tap: ControlEvent
- ThinkPHP5访问去除/public/index.php
- Java中private、protected、public和default的区别 (转)
- C++中的private, public, protected
- pysql public.res_partner 数据表备份血的教训 postgres数据库
- C++中public、protected及private使用方法
- C++于public、protected和private说明(From MSDN)
- JAVA修饰符类型(public,protected,private,friendly)
- MySQL 8.x 报错 Public Key Retrieval is not allowed 错误的解决方法