当前位置: 首页 > news >正文

成都创建公司网站让网站快速收录最新

成都创建公司网站,让网站快速收录最新,专业的网站设计制作公司,导航网站设计方案1.static 修饰符应用范围 static修饰符只能用来修饰类中定义的成员变量、成员方法、代码块以及内部类(内部类有专门章节进行讲解)。 2.static 修饰成员变量 static 修饰的成员变量称之为类变量。属于该类所有成员共享。 示例 package cn.lyxq.test04;public class Chinese…

1.static 修饰符应用范围

static修饰符只能用来修饰类中定义的成员变量、成员方法、代码块以及内部类(内部类有专门章节进行讲解)。

2.static 修饰成员变量

static 修饰的成员变量称之为类变量。属于该类所有成员共享。

示例

package cn.lyxq.test04;public class ChinesePeople {private String name;private  int age;public static String country = "中国";public ChinesePeople(String name,int age){this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}
package cn.lyxq.test04;public class ChinesePeopleTest {public static void main(String[] args) {ChinesePeople cp1 = new ChinesePeople("张三",20);System.out.println(ChinesePeople.country);ChinesePeople.country="日本";ChinesePeople cp2 = new ChinesePeople("李四",30);System.out.println(ChinesePeople.country);ChinesePeople cp3 = new ChinesePeople("王五",32);System.out.println(ChinesePeople.country);}}

如果类变量是公开的,那么可以使用 类名.变量名 直接访问该类变量

3.static 修饰成员方法

static 修饰的成员方法称之为类方法,属于该类所有成员共享。

package cn.lyxq.test04;public class ChinesePeople {private String name;private  int age;private static String country = "中国";public ChinesePeople(String name,int age){this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}//类方法public static String getCountry() {return country;}//类方法public static void setCountry(String country) {ChinesePeople.country = country;}
}
package cn.lyxq.test04;public class ChinesePeopleTest {public static void main(String[] args) {ChinesePeople cp1 = new ChinesePeople("张三",20);ChinesePeople.setCountry("日本");ChinesePeople cp2 = new ChinesePeople("李四",30);System.out.println(ChinesePeople.getCountry());ChinesePeople cp3 = new ChinesePeople("王五",32);System.out.println(cp3.getCountry());//不是最优访问方式}}

如果类方法是公开的,那么可以使用 类名.方法名直接访问该类方法。

4.static 修饰代码块

static 修饰的代码块被称为静态代码块,在JVM第一次记载该类时执行。因此,静态代码代码块只能执行一次,通常用于一些系统设置场景。

package cn.lyxq.test04;public class ChinesePeople {private String name;private  int age;//使用static修饰的成员变量称为类变量,不会随着成员变化而变化,属于所有成员共享private static String country ;//static修饰的代码块称为静态代码块,在JVM第一次加载该类的时候执行,只能执行一次static{country = "中国";System.out.println("country属性已经被赋值");}public ChinesePeople(String name,int age){this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}//类方法public static String getCountry() {return country;}//类方法public static void setCountry(String country) {ChinesePeople.country = country;}
}
package cn.lyxq.test04.test;import  cn.lyxq.test04.ChinesePeople;public class ChinesePeopleTest {public static void main(String[] args) {ChinesePeople cp = new ChinesePeople("张三",20);}}

5.static内存

http://www.yayakq.cn/news/997439/

相关文章:

  • 网站死链存在的问题世界500强企业国家排名
  • 青海省城乡建设厅网站首页哪个网站做视频挣钱
  • 网站设计作品做类似淘宝的网站要多少钱
  • 在线购物网站的设计中山市区做网站公司
  • 怎么做网站上做电子书网站绑定两个域名怎么做跳转
  • 公司网站对比那几点优势重庆好网互联
  • 动漫一级a做爰片免费网站wordpress 换图片地址
  • 东莞自助建站平台电商指的是什么行业
  • 英文企业网站源码 asp网站类游戏网站开发
  • 做简单网站后端需要学什么淄博网站推广优化
  • 网站建设维护学习网站网站开发公司
  • 建立网站策划虚拟主机如何建设多个网站
  • 网站模板样式修改美工网站设计
  • 网站建设哪家好灵活苏州久远网络大连承接网站制作
  • 如果让你建设网站之前你会想什么产品宣传
  • asp网站查看器宁波海曙建设局网站
  • 网站关键词 查询淮安市做网站的公司
  • 网站建设需要购买服务器么公司建设网站价格多少钱
  • 在哪里可以做网站赚钱asp技校网站
  • 外贸企业网站建设wordpress交友插件
  • 网站建设前景如何网站布局案例
  • 网站开发公司的职责高端网咖宣传语
  • 网站建设太金手指六六十一乐都企业网站建设公司
  • app跟网站的区别wordpress 评论 html
  • 建设企业网站可信度的具体策略网站的分类有哪些类型
  • 网站源码文件网站建设大庆
  • 大连网站建设哪个公司好广告视频
  • 网站建设排名优化公司哪家好河北邢台是不是很穷
  • wordpress 直播 视频郑州厉害的seo顾问
  • 网站建设及维护涉及哪些内容企业营销策划是什么意思