快捷键: Alt + Insert
package com.etc.ood; public class Person1 { //一个类即使什么都不写,也会存在一个方法 //显示的定义构造器 String name; int age; String hobby; //1.使用new关键字,本质是在调用构造器 //2.用来初始化值 public Person1() { } //有参构造:一旦定义了有参构造,无参必须显示定义 public Person1(String name, int age, String hobby) { this.name = name; this.age = age; this.hobby = hobby; } } package com.etc.ood; public class Application { public static void main(String[] args) { //实例化了一个对象 Person1 person1 = new Person1(); person1.name = "chen"; person1.age = 22; person1.hobby = "run"; System.out.println(person1.name); System.out.println(person1.age); System.out.println(person1.hobby); } }