package com.mypackage.oop.demo03;
public class Pet {
String name;
int age;
//无参构造
public void shout(){
System.out.println("叫了一声");
}
}
package com.mypackage.oop.demo03;
public class Application03 {
public static void main(String[] args) {
Pet dog = new Pet(); //实例化类,并调用
dog.name = "旺财";
dog.age = 3;
System.out.println(dog.name);
System.out.println(dog.age);
dog.shout(); //调用构造
}
}
//输出
旺财
3
叫了一声
进程已结束,退出代码0