JAVA CSS类

访问修饰符
public private protected 保护 默认 friendly

|---------------------------------|--------|----------|--------|------------|
| 访问修饰符 | 本类 | 同包下类 | 子类 | 其他实例对象 |
| private private int id; | √ | | | |
| 默认 (friendly 、 default) int id; | √ | √ | | |
| protected protected int id; | √ | √ | √ | |
| public public int id; | √ | √ | √ | √ |

java 复制代码
public class C2 {
/*属性 成员变量*/
public int id; //全局
private final int num = 18;//私有
protected String addr = "郑州";//受保护
String name = "jack";//友好,默认
}


静态属性,有时候类变量
/* 静态属性 类变量 */
public static int id = 3;
//静态 static 只分配一次内存


常量
/*常量 不能修改只能使用*/
public final int AGE = 18;


方法相关的概念(**)
public/*访问修饰权限*/ static/*静态方法,当前方法不用实例化对象,可以通过类型直接使用此方
法*/ void/*没有返回值*/ print/*方法名*/(/* 形参列表*/) {
//方法体
//return; 代表结束当前方法执行
}

无返回值 void修饰 ,方法内部可以使用 return ;随时结束方法执行
调用执行方法
相关推荐
小小鱼儿飞1 天前
QT音乐播放器18----新歌速递播放、隐藏顶部和底部工具栏、自定义ToolTips
开发语言·qt
穆雄雄1 天前
Rust 程序适配 OpenHarmony 实践:以 sd 工具为例
开发语言·rust·harmonyos
敏姐的后花园1 天前
模考倒计时网页版
java·服务器·前端
0***141 天前
Swift资源
开发语言·ios·swift
z***I3941 天前
Swift Tips
开发语言·ios·swift
J***Q2921 天前
Swift Solutions
开发语言·ios·swift
铅笔小新z1 天前
C++入门指南:开启你的编程之旅
开发语言·c++
Gavin-Wang1 天前
Swift + CADisplayLink 弱引用代理(Proxy 模式) 里的陷阱
开发语言·ios·swift
Dcs1 天前
Java 中 UnaryOperator 接口与 Lambda 表达式的应用示例
java·后端