概述
所有对象都可以引用静态方法
方法调用
变量赋值
代码
//Java-零基础学习/src/oop/demo03/Pet
package oop.demo03;
public class Pet {
public String name;
public int age;
//无参构造
public void shout() {
System.out.println("叫了一声");
}
}
/*
public static void main(String[] args) {
Pet dog = new Pet();
dog.name="旺财";
dog.age=3;
dog.shout();
System.out.println(dog.name);
System.out.println(dog.age);
Pet cat = new Pet();
}
*/
//Java-零基础学习/src/oop/Aoolication标签:分析,System,oop,Pet,dog,创建对象,内存,public,out From: https://www.cnblogs.com/poiuyjoey/p/17963105
package oop;
import oop.demo03.Pet;
//一个项目应该只存在一个main方法
public class Application {
public static void main(String[] args) {
Pet dog = new Pet();
dog.name = "旺财";
dog.age = 3;
dog.shout();
System.out.println(dog.name);
System.out.println(dog.age);
Pet cat = new Pet();
}
}