⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teststatic.java

📁 俄罗斯方块游戏java
💻 JAVA
字号:
//:TestStatic.java
public class TestStatic{
	public int instanceInteger=0;
	public int instanceMethod(){
		return instanceInteger;
	}
	public static int classInteger=0;
	public static int classMethod(){
		return classInteger;
	}
	public static void main(String[] args){//在这里创建自身的类
		//创建两个对象用于比较
		TestStatic anInstance=new TestStatic();
		TestStatic anotherInstance=new TestStatic();
		//分别对非静态属性赋值并输出
		anInstance.instanceInteger=1;
		anotherInstance.instanceInteger=2;
		System.out.print(anInstance.instanceMethod());
		System.out.print(anotherInstance.instanceMethod());
		//以类名对静态属性变量赋值并输出
		TestStatic.classInteger=7;
		System.out.print(classMethod());
		//以对象名调用,输出静态属性值System.out.println(anInstance.classMethod());
		System.out.print(anotherInstance.classMethod());
		//对象共用类的静态属性,改变其中一个对象的静态属性同类对象的该属性也改变
		anInstance.classInteger=9;
		System.out.print(anInstance.classMethod());
		System.out.println(anotherInstance.classMethod());
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -