static定义属性
static关键字在Java程序开发过程中主要进行属性和方法的定义。 static 定义属性: 类中的最主要的组成就是属性和方法,那么在说static之前,先看看一下问题: 范例:定义一个描述球的信息类: class Ball{ private String classify; private double price; private String brand; public Ball(String classify,double price,String brand){ this.classify = classify; this.price = price; this.brand = brand; } public void getInfo(){ System.out.println("球的类型:"+this.classify+"、价格:"+this.price+"、品牌:"+this.brand); }}public class Demo1{ public static void main(String[] args) { Ball basketball = new Ball("篮球",100,"李宁"); Ball football = new Ball("足球",101,"李宁"); Ball pingpang = new Ball("乒乓球",99,"李宁");