创建类
package entity;
public class Dog {
//静态特征 属性 成员变量 全局变量
public String name;
public int age;
public String type;
public String color;
public String sex;
//加public变成通用公共使用属性
//动态行为 方法(1.访问修饰符 2.返回值类型 3.方法名 4.形参列表 5.方法体)
public void eat() {
System.out.println("小狗吃骨头!!!");
}
public void run() {
//方法的调用
// 1.在同类中,方法直接调用方法名
// 2.在不同类中,方法需要创建的 对象.方法名
//方法作用
//1.完成代码的复用
//this在本类中可以省略不写
//show()
this.show();
System.out.println("小狗在奔跑。。。");
}
public void show() {
System.out.println("小狗信息");
//通配符this 表示当前对象
System.out.println("昵称:"+this.name+",年龄"+this.age);
}
}
创建对象
package test;
import entity.Dog;
public class TestDog {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num=10;//
int[] nums=new int[5];//
nums[0]=1;