您的位置:首页 > 编程语言 > Java开发

学习练习 java 实例属性 静态属性

2016-05-21 15:58 786 查看
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();
}

}




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: