12-调用类对象和有参构造和无参构造
新建了一个Cooker的对象
----
public class Cooker {
public Cooker(){
System.out.println("我是无参构造器");
}
// 构造器的重载
public Cooker(String na,int a,boolean ge, int gr){
name = na;
age = a;
grade = gr;
gender = ge;
System.out.println("我是传参构造器");
}
String name;
int age;
boolean gender;
int grade;
void cooking(){
System.out.println("可以做饭");
}
}
-------
调用 cooker 这个对象
import jdk.javadoc.internal.doclets.formats.html.SourceToHTMLConverter;
public class demo01 {
public static void main(String[] args) {
Cooker c1 = new Cooker();
Cooker c2 = new Cooker("zhang",32,false,6);
}
}