/**
* Created by xabcd on 2019/2/15.
*/
public class Person
{
String name;
int age;
void talk()
{
System.out.println("我是:"+name+",今年:"+age+"岁");
}
}
/**
* Created by xabcd on 2019/2/15.
*/
public class testPersonDemo2
{
public static void main(String args[]) {
//声明并实例化一个对象
Person p = new Person();
//给p中的属性赋值
p.name = "张三";
p.age = -25;
//调用Person类中的talk()方法
p.talk();
}
}
结果:
我是:张三,今年:-25岁
