学习练习 java 实例属性 静态属性
package com.hanqi;
public class Test11Car11 {
//静态
//实例属性
private int m = 0;
//静态属性
//所有实例共有的,在内存里只有一个
private static int n = 0 ;
//实例方法
public void run ()
{
for (int i = 0; i < 10; i++)
{
m++;
n++;
System.out.println("m = "+ m + " n = " + n);
}
}
//静态方法
public static void testStatic()
{
//访问内部成员
//m = 10;
n = 10;
//run()
Test11Car11 t1 = new Test11Car11();
t1.run();
System.out.println("测试静态方法");
//设计模式: 23种,单例模式,工厂模式,
}
}
package com.hanqi;
public class Test12 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
Test11Car11 t1 = new Test11Car11();
//实例方法
t1.run();
Test11Car11 t2 = new Test11Car11();
t2.run();
//调用类的静态方法
Test11Car11.testStatic();
//调用类的实例方法
//t1.testStatic();
System.out.println("t3 实例");
Test13 t3 = Test13.instance();
t3.run();
System.out.println("t4 实例");
Test13 t4 = Test13.instance();
t4.run();
}
}


学习练习 java 实例属性 静态属性的更多相关文章
- java类的静态属性值获取
获取某个类实例的静态属性: public class ErrorCode { private String code; private String message; private ErrorCod ...
- Python学习第十六课——静态属性(property, classmethod, staticmethod)
计算所居住房子的面积 普通写法 class Room: def __init__(self,name,owner,width,length,heigh): self.name=name self.ow ...
- Vue2.x源码学习笔记-Vue静态方法和静态属性整理
Vue静态方法和静态属性,其实直接在浏览器中可以查看到的,如下 圈起来的是其静态属性,但是有的属性对象中的属性的值又是函数.未圈起来的则是函数. 其实它来自如下各个目录下的js文件 // src/co ...
- Day 19:面向对象【类方法】静态属性/静态属性/类方法
静态属性 @property class Mom: gender = "woman" def __init__(self,name,weight): self.name = n ...
- 面向对象:静态属性,静态方法,组合,继承,衍生,继承之mro线性顺序列表,面向对象综合实例
1.静态属性(附有装饰器) class Room: def __init__(self,name,owner,width,length,height): self.name=name self.own ...
- php静态属性和静态方法
php静态属性和静态方法 2012-09-29 10:18 1518人阅读 评论(0) 收藏 举报 phpfunction 本php教程主要是学习php中静态属性和静态方法的使用方法和基本的示例. · ...
- python静态属性的理解
python中并没有像 C语言 C++ java 那样定义静态属性的关键字 static 那么在python中是怎么做的呢? class A(object): name="lance&quo ...
- day25、 静态属性、类方法、静态方法、组合、继承、
一. 静态属性.类方法.静态方法 1.1静态属性 class Room: def __init__(self,name,owner,width,length): self.name=name self ...
- python - class类 (二) 静态属性/类方法/静态方法
静态属性: #静态属性 = 数据属性 (@property) class mianji(): def __init__(self,x,y): self.x = x self.y = y #类的函数方法 ...
随机推荐
- Source insight 3572版本安装及An invalid source insight serial number was detected解决方法
Source insight有最新版3572.3.50.0076 下载连接:http://www.sourceinsight.com/down35.html, http://www.sourcei ...
- 105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. ============== 基本功: 利用前序和 ...
- HashMap 实现详解
HashMap是哈希表对Map非线程安全版本的实现,它允许key为null,也允许value为null.所谓哈希表就是通过一个哈希函数计算出一个key的哈希值,然后使用该哈希值定位对应的value所在 ...
- PLSQL_Oracle Trigger触发器的基本概念和用法
2014-06-14 Created By BaoXinjian
- ADO.NET(完整修改和查询、实体类,数据访问类)
一.完整修改和查询 在编写c#语句时需考虑到用户体验,例如在编写修改语句时,需要考虑到输入的内容在数据库中是否能够找到. 中间变量运用. 1.先查 2.执行操作 完整修改语句: bool has = ...
- Tornado (and Twisted) in the age of asyncio》
Tornado (and Twisted) in the age of asyncio>
- bug_ _fragment的1
========= 2 fragment小结 ???? ======== 1 fragment:java.lang.IllegalStateException: Can not perf ...
- studio_ 优化Android Studio 启动、编译和运行速度?
http://www.admin10000.com/document/6842.html: 作为一名 Android 程序员,选择一个好的 IDE 工具可以使开发变得非常高效,很多程序员喜欢使用 Go ...
- jquery extend中
var $=123; <src="jquery.js"> //加载jquery.js的时候 里面有句 _$=window.$,保存123的 //no ...
- ConcurrentHashMap使用要点
ConcurrentHashMap的简要总结: 1.public V get(Object key)不涉及到锁,也就是说获得对象时没有使用锁: 2.put.remove方法要使用锁,但并不一定有锁争用 ...