掌握有无stctic修饰成员变量的用法、特点
package com.StaticDemo; public class Student { //类变量也是静态变量 static String name; //实例变量
也叫对象变量
int age; }
package com.StaticDemo; public class Test { public static void main(String[] args) { //掌握有无stctic修饰成员变量的用法、特点 /**类变量:有static,属于类,在计算机里只有一份,会被类的全部对象共享 * 实例变量(对象的变量):无static修饰,属于每个对象的 * * */ //1.类变量的用法 //类名.类变量(推荐) Student.name="袁华"; //对象.类变量(不推荐) Student s1=new Student(); s1.name="马冬梅"; Student s2=new Student(); s2.name="秋雅"; System.out.println(s1.name);//秋雅 System.out.println(Student.name);//秋雅 //2.实例变量的用法 //对象.实例变量 s1.age=23; s2.age=18; System.out.println(s1.age);//23 // System.out.println(Student.age);//报错 } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现